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

Commit edadda1

Browse files
Merge pull request #32 from dhadka/dhadka/typed-error
Throw HttpClientError instead of Error
2 parents 544584c + e949b05 commit edadda1

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.8
47
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)
58

index.ts

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

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

745-
let err: Error = new Error(msg)
746-
747-
// attach statusCode and body obj (if available) to the error object
748-
err['statusCode'] = statusCode
749-
if (response.result) {
750-
err['result'] = response.result
751-
}
757+
let err = new HttpClientError(msg, statusCode)
758+
err.result = response.result
752759

753760
reject(err)
754761
} 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.8",
3+
"version": "1.0.9",
44
"description": "Actions Http Client",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)