Skip to content

Errors module

Dmitry Usik edited this page Apr 3, 2022 · 7 revisions

🤔 Intro

Errors module has been developed in order to control the errors throughout the app.

Error screen

In the current implementation, if some component caught an error then the ErrorScreen would be shown. You can customize it as you need.

❌ Errors

📵 Runtime error

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.message by default.
  • details - custom error details. {} by default.

🚫 HttpRequest error

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.message by default.
  • details - custom error details. {} by default.

🔞 Validation error

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.message by default.
  • details - custom error details. {} by default.

Usage

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);
}

Clone this wiki locally