New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

error-to-message

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error-to-message

All caught errors to UI ready messages

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

Error to Message

As the name, it take whatever error and return a String for display in front-end.

🚨Still in development, have not tested yet.

I want a function that could take care the caught all type of error and return a string, just like that and tried to write the helper error handler function cross project.

Developing Road map:

  • Sending email for unexpected errors

Install

npm install error-to-message
# or
yarn add error-to-message

Example

Basic

const { toMessage } = require("error-to-message");
// ES2015
import { toMessage } from "error-to-message";

try {
  // throw error
} catch (e) {
  // uses as String
  <Notification message={toMessage(e)} />;
}

Advanced

import { newErrorMessage, errorAxios } from "error-to-message";

// 01, Optional, {Function} write your own errorHandler if needs
/** @returns {String} */
const myCustomizedErrorHandler = error => {
  if (typeof error === "object" && error.customizedKey)
    return error.customizedMsgString;
  else return error;
};

// 02, Optional, {String} write you own fallbackMessage
const fallbackMessage = "Oops, something went wrong, please try again";

// 03, Composing errorHandlers as what you needs
const toMessage = error =>
  newErrorMessage(fallbackMessage)(
    myCustomizedErrorHandler,
    errorAxios
    // ...other handlers
  )(error);

try {
  // throw error
} catch (e) {
  // uses as String
  <Notification message={toMessage(e)} />;
}

Keywords

error

FAQs

Package last updated on 21 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts