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

stringifiable-error

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stringifiable-error

Allow instances of Error to be serialized implicitly by JSON.stringify()

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

Stringifiable Error

Enhances Error.prototype with a toJSON() method so that errors can be serialized without explicit transformation.

Installation

npm install stringifiable-error

Usage

You only need to import (or require()) 'stringifiable-error' for its side effects once, typically in the primary entry point to your program.

import 'stringifiable-error'

Then, wherever you need to serialize an error, JSON.stringify() will work.

try {
  // ...
} catch (error) {
  // `logger` serializes `error` before saving it.
  logger.error(error)
}

// The serialized error:
//
// {
//   "type": "AssertionError",
//   "message": "`3 + 5` is `7`",
//   "stack": [
//     "fn (/.../src/client.ts:35:3)",
//     "Object.<anonymous> (/.../src/client.ts:40:3)",
//     "Module._compile (module.js:649:30)",
//     "Module.m._compile (/.../node_modules/ts-node/src/index.ts:403:23)",
//     "Module._extensions..js (module.js:660:10)",
//     "Object.require.extensions.(anonymous function) [as .ts] (/.../node_modules/ts-node/src/index.ts:406:12)",
//     "Module.load (module.js:561:32)",
//     "tryModuleLoad (module.js:501:12)",
//     "Function.Module._load (module.js:493:3)",
//     "Function.Module.runMain (module.js:690:10)"
//   ],
//   "actual": false,
//   "code": "ERR_ASSERTION",
//   "expected": true,
//   "generatedMessage": false,
//   "name": "AssertionError [ERR_ASSERTION]",
//   "operator": "=="
// }

Keywords

json

FAQs

Package last updated on 27 May 2018

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