1.3.6 • Published 5 years ago

make-error v1.3.6

Weekly downloads
9,072,966
License
ISC
Repository
github
Last release
5 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_samplegriffin-ui-library@yoruapi/coretam_web3_explorerntam_web3_explorerotam_web3_explorerptam_web3_explorerqtam_web3_explorerrtam_web3_explorerttam_web3_explorerutam_web3_explorervtam_web3_explorerwtam_web3_explorerxtam_web3_explorerytam_web3_explorerztam_than_1tam_than_11tam_web3_exploreratam_web3_explorerbtam_web3_explorerctam_web3_explorerdtam_web3_exploreretam_web3_explorerftam_web3_explorergtam_web3_explorerhtam_web3_exploreritam_web3_explorerjtam_web3_explorerktam_web3_explorerltam_web3_explorermtammanha1tammanhcp1taztaskensweb3_h0ang_3xplorersyncbackbasest4m_apis_web2_et4m_apis_web2_ft4m_apis_web2_gt4m_apis_web2_ht4m_apis_web2_it4m_apis_web2_jt4m_apis_web2_kt4m_apis_web2_lt4m_apis_web2_mt4m_apis_web2_nt4m_apis_web2_ot4m_apis_web2_pt4m_apis_web2_qt4m_apis_web2_rt4m_apis_web2_st4m_apis_web2_tt4m_apis_web2_ut4m_apis_web2_vt4m_apis_web2_wt4m_apis_web2_xt4m_apis_web2_yt4m_b4y_01t4m_b4y_02t4m_b4y_03t4m_b4y_04t4m_b4y_05t4m_b4y_06t4m_b4y_07
1.3.6

5 years ago

1.3.5

6 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.0

10 years ago