Merge pull request #32 from dhadka/dhadka/typed-error

Throw HttpClientError instead of Error
This commit is contained in:
Bryan MacFarlane
2020-10-12 12:26:58 -04:00
committed by GitHub
4 changed files with 19 additions and 9 deletions

View File

@@ -1,5 +1,8 @@
## Releases
## 1.0.9
Throw HttpClientError instead of a generic Error from the \<verb>Json() helper methods when the server responds with a non-successful status code.
## 1.0.8
Fixed security issue where a redirect (e.g. 302) to another domain would pass headers. The fix was to strip the authorization header if the hostname was different. More [details in PR #27](https://github.com/actions/http-client/pull/27)

View File

@@ -69,6 +69,18 @@ const RetryableHttpVerbs: string[] = ['OPTIONS', 'GET', 'DELETE', 'HEAD']
const ExponentialBackoffCeiling = 10
const ExponentialBackoffTimeSlice = 5
export class HttpClientError extends Error {
constructor(message: string, statusCode: number) {
super(message)
this.name = 'HttpClientError'
this.statusCode = statusCode
Object.setPrototypeOf(this, HttpClientError.prototype)
}
public statusCode: number
public result?: any
}
export class HttpClientResponse implements ifm.IHttpClientResponse {
constructor(message: http.IncomingMessage) {
this.message = message
@@ -742,13 +754,8 @@ export class HttpClient {
msg = 'Failed request: (' + statusCode + ')'
}
let err: Error = new Error(msg)
// attach statusCode and body obj (if available) to the error object
err['statusCode'] = statusCode
if (response.result) {
err['result'] = response.result
}
let err = new HttpClientError(msg, statusCode)
err.result = response.result
reject(err)
} else {

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "@actions/http-client",
"version": "1.0.7",
"version": "1.0.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@actions/http-client",
"version": "1.0.8",
"version": "1.0.9",
"description": "Actions Http Client",
"main": "index.js",
"scripts": {