Return HttpClientError instead of Error, have properties for status and result
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
## Releases
|
## 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.7
|
## 1.0.7
|
||||||
Update NPM dependencies and add 429 to the list of HttpCodes
|
Update NPM dependencies and add 429 to the list of HttpCodes
|
||||||
|
|
||||||
|
|||||||
21
index.ts
21
index.ts
@@ -70,6 +70,18 @@ const RetryableHttpVerbs: string[] = ['OPTIONS', 'GET', 'DELETE', 'HEAD']
|
|||||||
const ExponentialBackoffCeiling = 10
|
const ExponentialBackoffCeiling = 10
|
||||||
const ExponentialBackoffTimeSlice = 5
|
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 {
|
export class HttpClientResponse implements ifm.IHttpClientResponse {
|
||||||
constructor(message: http.IncomingMessage) {
|
constructor(message: http.IncomingMessage) {
|
||||||
this.message = message
|
this.message = message
|
||||||
@@ -733,13 +745,8 @@ export class HttpClient {
|
|||||||
msg = 'Failed request: (' + statusCode + ')'
|
msg = 'Failed request: (' + statusCode + ')'
|
||||||
}
|
}
|
||||||
|
|
||||||
let err: Error = new Error(msg)
|
let err = new HttpClientError(msg, statusCode)
|
||||||
|
err.result = response.result
|
||||||
// attach statusCode and body obj (if available) to the error object
|
|
||||||
err['statusCode'] = statusCode
|
|
||||||
if (response.result) {
|
|
||||||
err['result'] = response.result
|
|
||||||
}
|
|
||||||
|
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/http-client",
|
"name": "@actions/http-client",
|
||||||
"version": "1.0.7",
|
"version": "1.0.9",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/http-client",
|
"name": "@actions/http-client",
|
||||||
"version": "1.0.7",
|
"version": "1.0.9",
|
||||||
"description": "Actions Http Client",
|
"description": "Actions Http Client",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user