Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Commit 55850f1

Browse files
committed
Return HttpClientError instead of Error, have properties for status and result
1 parent ab10999 commit 55850f1

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

RELEASES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Releases
22

3+
## 1.0.9
4+
Throw HttpClientError instead of a generic Error from the \<verb>Json() helper methods when the server responds with a non-successful status code.
5+
36
## 1.0.7
47
Update NPM dependencies and add 429 to the list of HttpCodes
58

index.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ const RetryableHttpVerbs: string[] = ['OPTIONS', 'GET', 'DELETE', 'HEAD']
7070
const ExponentialBackoffCeiling = 10
7171
const ExponentialBackoffTimeSlice = 5
7272

73+
export class HttpClientError extends Error {
74+
constructor(message: string, statusCode: number) {
75+
super(message)
76+
this.name = 'HttpClientError'
77+
this.statusCode = statusCode
78+
Object.setPrototypeOf(this, HttpClientError.prototype)
79+
}
80+
81+
public statusCode: number
82+
public result?: any
83+
}
84+
7385
export class HttpClientResponse implements ifm.IHttpClientResponse {
7486
constructor(message: http.IncomingMessage) {
7587
this.message = message
@@ -733,13 +745,8 @@ export class HttpClient {
733745
msg = 'Failed request: (' + statusCode + ')'
734746
}
735747

736-
let err: Error = new Error(msg)
737-
738-
// attach statusCode and body obj (if available) to the error object
739-
err['statusCode'] = statusCode
740-
if (response.result) {
741-
err['result'] = response.result
742-
}
748+
let err = new HttpClientError(msg, statusCode)
749+
err.result = response.result
743750

744751
reject(err)
745752
} else {

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/http-client",
3-
"version": "1.0.7",
3+
"version": "1.0.9",
44
"description": "Actions Http Client",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)