Skip to content

Commit

Permalink
Add error handler (#609)
Browse files Browse the repository at this point in the history
* feature:add handler

Signed-off-by: capyq <quentin.capy@rte-france.com>
  • Loading branch information
capyq authored Nov 12, 2024
1 parent 868b030 commit b74ff4d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ export const backendFetchJson = (url: string, init: any, token?: string) => {
export const getRequestParamFromList = (paramName: string, params: string[] = []) => {
return new URLSearchParams(params.map((param) => [paramName, param]));
};

export const catchErrorHandler = (error: unknown, callback: (message: string) => void) => {
if (error instanceof Object && 'message' in error && typeof error.message === 'string') {
callback(error.message);
} else {
callback('unknown error');
}
};

0 comments on commit b74ff4d

Please sign in to comment.