ym-error-code v1.0.0
REST API Error Messages Generator - Module to automate and standardize error messages on REST API based services.
Installation
$ npm i ym-error-code --save
Implementation
Adding New Error
You can add your custom error codes on the class instantiation.
//Import; //Instantiation, with new error codesconst Error = "1": "code": 1 "details": "New Error" "message": "en": "Your new error message" "my": "သီဟိုဠ်မှ ဉာဏ်ကြီးရှင်သည် အာယုဝဍ္ဎနဆေးညွှန်းစာကို ဇလွန်ဈေးဘေး ဗာဒံပင်ထက် အဓိဋ္ဌာန်လျက် ဂဃနဏဖတ်ခဲ့သည်။" "2": "code": 2 "details": "New Error 2" "message": "en": "Your new error message 2" "my": "သီဟိုဠ်မှ ဉာဏ်ကြီးရှင်သည် အာယုဝဍ္ဎနဆေးညွှန်းစာကို ဇလွန်ဈေးဘေး ဗာဒံပင်ထက် အဓိဋ္ဌာန်လျက် ဂဃနဏဖတ်ခဲ့သည်။" ; Error; /* will return { "code": 1, "details": "New Error", "message": "Your new error message" }*/
Warning: If your new error code are the same with the existing error code, the existing error code will be overridden.
Internationalization
By default, ym-error-code
message comes with English (United States) locale strings. If you need other locales, pass the key and the string value on the class instantiation.
//Import; //Instantiation, english by defaultconst Error = ; //Instantiation with Burmese as default languageconst Error = null 'my'; //pass the locale stringError;
Note: Currently, the available languages for displaying error messages are English ('en') and Myanmar ('my').
Basic usage
Error; /* will return { "code": 200, "details": "Ok", "message": "Request has successfully been completed." }*/
Using Custom Error Message
You can change the error message with your custom message.
Error; /* will return { "code": 200, "details": "Ok", "message": "Your custom message" }*/