@tap-payments/web-error-handing
v1.0.1
Published
Web Error Handling Library
Downloads
671
Maintainers
Keywords
Readme
Web-Error-Handing
It's a package that helps you to handle errors in your web applications.
Install
This is a React module available through the
npm registry. Installation is done using the
npm install
command:
npm install @tap-payments/web-error-handing
---------------------------- OR -------------------------
yarn add @tap-payments/web-error-handing
Examples
import { WebErrorHandler, ClientError } from "@tap-payments/web-error-handing"
try {
// throw error with only message
throw new Error("Error Message")
} catch (error) {
const error = new WebErrorHandler(error)
console.log(error.getClientError()) // {code: "Unknown", message: "Error Message"}
}
// OR
try {
// throw error with code and message
throw new Error("500::Error Message")
} catch (error) {
const error = new WebErrorHandler(error)
console.log(error.getClientError()) // {code: "500", message: "Error Message"}
}
// OR
try {
// network error
await axios.get("https://api.tap.company/v2/tokens")
} catch (error) {
// it will return the error object from the response.data.errors and map it to the error object ClientError
const error = new WebErrorHandler(error)
console.log(error.getClientError()) // {code: "{{backend_code}}", message: "{{backend_description}}"}
console.log(error.getCode()) // {{backend_code}}
console.log(error.getMessage()) // {{backend_description}}
}
// OR
const error = new WebErrorHandler("500::Error Message")
console.log(error.getClientError()) // {code: "500", message: "Error Message"}
console.log(error.getCode()) // "500"
console.log(error.getMessage()) // "Error Message"