1.3.6 • Published 4 years ago

make-error v1.3.6

Weekly downloads
9,072,966
License
ISC
Repository
github
Last release
4 years ago

make-error

Package Version Build Status PackagePhobia Latest Commit

Make your own error types!

Features

  • Compatible Node & browsers
  • instanceof support
  • error.name & error.stack support
  • compatible with CSP (i.e. no eval())

Installation

Node & Browserify/Webpack

Installation of the npm package:

> npm install --save make-error

Then require the package:

var makeError = require("make-error");

Browser

You can directly use the build provided at unpkg.com:

<script src="https://unpkg.com/make-error@1/dist/make-error.js"></script>

Usage

Basic named error

var CustomError = makeError("CustomError");

// Parameters are forwarded to the super class (here Error).
throw new CustomError("a message");

Advanced error class

function CustomError(customValue) {
  CustomError.super.call(this, "custom error message");

  this.customValue = customValue;
}
makeError(CustomError);

// Feel free to extend the prototype.
CustomError.prototype.myMethod = function CustomError$myMethod() {
  console.log("CustomError.myMethod (%s, %s)", this.code, this.message);
};

//-----

try {
  throw new CustomError(42);
} catch (error) {
  error.myMethod();
}

Specialized error

var SpecializedError = makeError("SpecializedError", CustomError);

throw new SpecializedError(42);

Inheritance

Best for ES2015+.

import { BaseError } from "make-error";

class CustomError extends BaseError {
  constructor() {
    super("custom error message");
  }
}

Related

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet

ts-nodets-jest@endemolshinegroup/cosmiconfig-typescript-loader@xrnoz/ts-nodecuc-gaf@nmh/myanmar-cities-townshipsarchetype-libraryeasy-select-rn@oneplanetcrowd/developers@sellics/rankings@alaka/notificationsts-node031@aries-framework/core-testgql_din_modbitget@jttechnic/interpreter@lanetix/layout-validator@lanetix/list-query-mapper@lanetix/odata-ast-transformationstypes-gis@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-test@oiti/documentoscopy-react-nativequoc-test@iacoshoria/datastore@prodam/prodam-typesexpand-react-bridgeluminos-ui-core@everything-registry/sub-chunk-2124jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkg@gmogshd-cto-office/credo-corereact-native-jawwy_samplek0mmand3rlib-errorlibcatkhot-zone-vuehong1-utilskhaled-salem-custom-componentskns-error-codekomondorkomondor-pluginkube-smoke-testlbprintiex-sdkiris-colorsjamuskalimjeopardyconverterjordy-frijters-test-liblog4debugmoonwalkerswap-default-token-listsnode-finagleniftycloud-authnew-example-projectng-search-dropdownnode-ph-locationsnode-postgres-patchnglogger-acefoneluis-entity-builderluis-response-buildermarktionmobtimer-api2mongo2elasticmollu-lang-webmpesa-cookiempesa-cookie-jarmsand-apollo-cache-hermesjsonrpc-websocket-clientjrennsoh88-react-native-scroll-indicatorjson-rpc-protocolk-syncnative-date-picker-modulenative-modal-damage-vehiclenativescript-bluetoothnd-json-rpc-protocolmy-greeter-packagenew-awesome-4321lv_font_convmake-error-causemama-exporterlq-server-clinoelnotion-database-exporternpm-package-mentorcheckn8n-nodes-caldavmd-vditor@vates/xw-api-errors@vandai-nguyen/module_test@traitsniper/web3-react-connector@traitsniper/web3-react-v6-connector@remirror/core-helpers@react-native-ui-design/button@soodam.re/env-utils@soundation/sharedb@recro/easy-kubernetes-controller@regressionhub/types
1.3.6

4 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.0

9 years ago