Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
more generalized errors from forDefi client
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeychr committed Nov 30, 2023
1 parent 657a852 commit 9ee0afa
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/authority-forDefi/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ export class ForDefiClient {
if (!response.ok) {
const error = <ErrorResponse>parsedData;
logger.debug(
`response is not Ok: code: ${response}, details: ${error?.title} (${error?.detail}), body: ${parsedData}`,
);
throw new Error(
`forDefi returned unexpected response code: ${response}; ${error?.title} (${error?.detail})`,
`response for requestId: ${error.request_id} is not Ok: code: ${response.status}, details: ${error?.title} (${error?.detail}), body: ${parsedData}`,
);
throw new Error(`forDefi returned error: ${error?.title} (${error?.detail})`);
}

logger.trace(parsedData);
Expand All @@ -108,8 +106,8 @@ export class ForDefiClient {
try {
return JSON.parse(body);
} catch (e) {
logger.error(`forDefi returned unrecognizable text: ${body}`);
throw new Error(`forDefi returned unrecognizable text: ${body}`);
logger.error(`response is not JSON: ${body}`);
throw new Error(`forDefi returned unexpected data: ${body}`);
}
}

Expand Down Expand Up @@ -138,9 +136,9 @@ export class ForDefiClient {
const response = await fetch(`https://${this.apiHost}${path}`, request);
return response;
} catch (e) {
logger.error(`error calling forDefi ${path}: ${e}`);
logger.error(`request to ${path} failed: ${e}`);
logger.error(e);
throw e;
throw new Error(`forDefi failed to respond: ${e}`);
} finally {
// track request timing
const elapsedTime = new Date().getTime() - startedAt;
Expand Down

0 comments on commit 9ee0afa

Please sign in to comment.