1.13.0 • Published 3 years ago

@wefloc/api-codes v1.13.0

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

api-codes

PRs Welcome

Description

This repository provides an interface to easily understand back-end errors from client point of view. Error codes and their translations are centralized in this repository.

Install

yarn add @wefloc/api-codes

How to use it?

API response

The API use the following schema to return an error.

{
  "errorKey": "carts:client:cartNotFound",
  "errorMessage": "Cart was not found"
}

You can then use the errorKey as follow :

import errors from '@wefloc/api-codes';

// Get all codes
errors.getAll();

// Get one error using its error key
errors.get('orders:client:invalidEmail'); // string must match <resource>:<scope>:<message>
errors.get('not-an-error'); // => throws an error

An error is defined as below

interface IFullCode {
  status: EHttpCode; // HTTP response code
  i18n: (lang?: ELocal) => string;
}

You can also get the i18n translation of each error message.

English is defined as the default language so calling .i18n() without argument will return the english translation by default.

errors.get('orders:client:cartTripNotFound').i18n(); // => string
errors.get('orders:client:cartTripNotFound').i18n('fr'); // => string
errors.get('orders:client:cartTripNotFound').i18n('en'); // => string
errors.get('orders:client:cartTripNotFound').i18n('Not-A-Language'); // => throws an error

Scripts

Run using yarn run <script> command.

clean       - Remove temporarily folders.
build       - Compile source files.
build:watch - Interactive watch mode, compile sources on change.
lint        - Lint source files.
lint:fix    - Fix lint source files.
test        - Runs all tests with coverage.
test:watch  - Interactive watch mode, runs tests on change.

License

MIT © Dimitri DO BAIRRO

1.13.0

3 years ago

1.12.0

3 years ago

1.11.1

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.11.0

3 years ago

1.6.0

3 years ago

1.10.0

3 years ago

1.5.0

3 years ago