Skip to content

Commit

Permalink
fix: remove response message prop name from http error message (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
DNR500 authored Jul 22, 2024
1 parent dbec40c commit 6ddd1ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/errors/SDKError.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('SDKError', () => {
}

expect(() => testFunction()).toThrowError(
`[HTTPError] [ValidationError] Request failed with status code 400 Bad Request\n responseMessage: Oops\nLI.FI SDK version: ${version}`
`[HTTPError] [ValidationError] Request failed with status code 400 Bad Request. Oops\nLI.FI SDK version: ${version}`
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/errors/httpError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export class HTTPError extends BaseError {
try {
this.responseBody = await this.response.json()

const spacer = '\n '

if (this.responseBody) {
this.message += `${spacer}responseMessage: ${this.responseBody?.message.toString().replaceAll('\n', spacer)}`
this.message += this.message.endsWith('.')
? ` ${this.responseBody?.message.toString()}`
: `. ${this.responseBody?.message.toString()}`
}
} catch {}

Expand Down
15 changes: 5 additions & 10 deletions src/errors/httpError.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ describe('HTTPError', () => {
code: LiFiErrorCode.ValidationError,
jsonFunc: () => Promise.resolve(responseBody),
responseBody,
builtMessage: `[ValidationError] Request failed with status code 400 Bad Request
responseMessage: Oops`,
builtMessage: `[ValidationError] Request failed with status code 400 Bad Request. Oops`,
},
],
[
Expand All @@ -34,8 +33,7 @@ describe('HTTPError', () => {
code: LiFiErrorCode.NotFound,
jsonFunc: () => Promise.resolve(responseBody),
responseBody,
builtMessage: `[NotFoundError] Request failed with status code 404 Not Found
responseMessage: Oops`,
builtMessage: `[NotFoundError] Request failed with status code 404 Not Found. Oops`,
},
],
[
Expand All @@ -50,8 +48,7 @@ describe('HTTPError', () => {
code: LiFiErrorCode.SlippageError,
jsonFunc: () => Promise.resolve(responseBody),
responseBody,
builtMessage: `[SlippageError] Request failed with status code 409 Conflict\nThe slippage is larger than the defined threshold. Please request a new route to get a fresh quote.
responseMessage: Oops`,
builtMessage: `[SlippageError] Request failed with status code 409 Conflict\nThe slippage is larger than the defined threshold. Please request a new route to get a fresh quote. Oops`,
},
],
[
Expand All @@ -66,8 +63,7 @@ describe('HTTPError', () => {
code: LiFiErrorCode.InternalError,
jsonFunc: () => Promise.resolve(responseBody),
responseBody,
builtMessage: `[ServerError] Request failed with status code 500 Internal Server Error
responseMessage: Oops`,
builtMessage: `[ServerError] Request failed with status code 500 Internal Server Error. Oops`,
},
],
[
Expand All @@ -81,8 +77,7 @@ describe('HTTPError', () => {
code: LiFiErrorCode.InternalError,
jsonFunc: () => Promise.resolve(responseBody),
responseBody,
builtMessage: `[ServerError] Request failed with an unknown error
responseMessage: Oops`,
builtMessage: `[ServerError] Request failed with an unknown error. Oops`,
},
],
[
Expand Down

0 comments on commit 6ddd1ad

Please sign in to comment.