Skip to content

Commit

Permalink
Merge pull request #2 from nikksan/main
Browse files Browse the repository at this point in the history
Add the response body to the HttpStatusCodeError
  • Loading branch information
tecs committed Jan 19, 2021
2 parents 3a159d3 + e7d817d commit cb535a3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
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": "@luckbox/http-adapter-factory",
"version": "1.0.0",
"version": "1.0.1",
"description": "Easy to use http adapter factory with support for GET/POST.",
"author": "Luckbox",
"main": "dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/GotHttpAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class GotHttpAdapter implements HttpAdapter {
throw new HttpStatusCodeError({
message: err.message,
statusCode: err.response.statusCode,
body: err.response.body,
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/errors/HttpStatusCodeError.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
type ConstructorParams = {
statusCode: number,
message: string,
body: unknown,
}

class HttpStatusCodeError extends Error {
public readonly statusCode: number;
public readonly message: string;
public readonly body: unknown;

constructor(params: ConstructorParams) {
super(params.message);

this.name = 'HttpStatusCodeError';
this.statusCode = params.statusCode;
this.body = params.body;
}

isTooManyRequests(): boolean {
Expand Down

0 comments on commit cb535a3

Please sign in to comment.