Skip to content

Commit

Permalink
Simplifying alert logic
Browse files Browse the repository at this point in the history
  • Loading branch information
teresaqhoang committed Sep 19, 2023
1 parent c819b54 commit d8f8a2d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions webapp/src/libs/services/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ export class BaseService {
});

if (!response.ok) {
const responseText = await response.text();

if (response.status === 504) {
throw Object.assign(new Error('The request timed out. Please try sending your message again.'));
}

const errorMessage = `${response.status}: ${response.statusText}${
responseText ? ` => ${responseText}` : ''
}`;
const responseText = await response.text();
const responseDetails = responseText.split('--->');
const errorDetails =
responseDetails.length > 1
? `${responseDetails[0].trim()} ---> ${responseDetails[1].trim()}`
: responseDetails[0];
const errorMessage = `${response.status}: ${response.statusText}${errorDetails}`;

throw Object.assign(new Error(errorMessage));
}
Expand Down

0 comments on commit d8f8a2d

Please sign in to comment.