-
Notifications
You must be signed in to change notification settings - Fork 2
Errors module
Dmitry Usik edited this page Apr 3, 2022
·
7 revisions
Errors module has been developed in order to control the errors throughout the app.
In the current implementation, if some component caught an error then the ErrorScreen would be shown. You can customize it as you need.
This type of error could be used in order to handle any errors in the app.
new RuntimeError(code, message, details):
-
code- a unit of ErrorCode. -
message- custom message.error.messageby default. -
details- custom error details.{}by default.
This type of error could be used in order to handle HTTP request errors in the app.
new HttpRequestError(httpStatusCode, message, details):
-
httpsStatusCode- a unit of HttpStatusCode. -
message- custom message.error.messageby default. -
details- custom error details.{}by default.
This type of error could be used in order to handle any validation errors in the app.
new ValidationError(code, message, details):
-
code- a unit of ErrorCode. -
message- custom message.error.messageby default. -
details- custom error details.{}by default.
At first, you need to implement a function that will parse errors. Use this as an example:
import { errorsParsers } from '~modules/errors'
export const parseError = (error: unknown) => {
const parsedError = errorsParsers.parseError(error);
logError(parsedError);
return parsedError;
};Then, throw an error where it's needed:
try {
if (someCondition) throw new RuntimeError(someErrorCode);
} catch(error) {
throw parseError(error);
}