Skip to content

Commit

Permalink
Use Response.rawBody when throwing ParseError
Browse files Browse the repository at this point in the history
  • Loading branch information
Todor Petrov committed Apr 20, 2021
1 parent 418982a commit 278515f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/GotHttpAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class GotHttpAdapter implements HttpAdapter {
if (err instanceof GotParseError) {
throw new ParseError({
message: err.message.split(/\sin\s+"?https?:\/{2}/i, 1)[0],
responseBody: err.response.body,
responseBody: err.response.rawBody.toString(),
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/errors/ParseError.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
type ConstructorParams<ResponseBodyType = unknown> = {
type ConstructorParams = {
message: string;
responseBody: ResponseBodyType;
responseBody: string;
}

class ParseError<ResponseBodyType = unknown> extends Error {
public readonly responseBody: ResponseBodyType;
class ParseError extends Error {
public readonly responseBody: string;

constructor(params: ConstructorParams<ResponseBodyType>) {
constructor(params: ConstructorParams) {
super(params.message);

this.name = 'ParseError';
Expand Down
4 changes: 2 additions & 2 deletions src/tests/GotHttpAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('GotHttpAdapter', () => {
message: 'Unexpected token < at position 10 in "http://example.com"',
name: 'ParseError',
response: {
body: 'Invalid JSON',
rawBody: Buffer.from('Invalid JSON'),
},
});

Expand Down Expand Up @@ -383,7 +383,7 @@ describe('GotHttpAdapter', () => {
message: 'Unexpected token < at position 10 in "http://example.com"',
name: 'ParseError',
response: {
body: 'Invalid JSON',
rawBody: Buffer.from('Invalid JSON'),
},
});

Expand Down

0 comments on commit 278515f

Please sign in to comment.