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

Commit

Permalink
Merge pull request #32 from dhadka/dhadka/typed-error
Browse files Browse the repository at this point in the history
Throw HttpClientError instead of Error
  • Loading branch information
bryanmacfarlane authored Oct 12, 2020
2 parents 544584c + e949b05 commit edadda1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
21 changes: 14 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/http-client",
"version": "1.0.8",
"version": "1.0.9",
"description": "Actions Http Client",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit edadda1

Please sign in to comment.