Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove response message prop name from http error message #202

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading