2.0.0-beta1 • Published 1 year ago

@huds0n/error v2.0.0-beta1

Weekly downloads
168
License
MIT
Repository
-
Last release
1 year ago

Status GitHub Issues GitHub Pull Requests License


📝 Table of Contents

🧐 About

Error Class extending on JavaScript's Error, adding in additional properties, such as: code, severity, handled, ect...

Used throughout the Huds0n modules libary.

✅ List of Features

  • Informative: Adds typed props for code, severity, info, and more.
  • Current: Easily updated or flagged as handled.
  • Lossless: Update history is stored.
  • Typed: Fully integrated with typescript out-of-the-box.
  • Transferable: Built-in methods to JSON stringify and parse.

🏁 Getting Started

Installing

npm i @huds0n/error

🧑‍💻 Basic Usage

Creating an Error

import { Huds0nError } from '@huds0n/error';

// Or with node

const { HudsonError } = require('@huds0n/error');

const exampleError = new Huds0nError(errorProps);

See reference for errorProps

Handling an Error

exampleError.handled(handledProps);

Handled props is an optional object that adds handled info to the error.

Updating an Error

exampleError.update(props);

The new properties are added to the error. Overwritten properties are pushed to the update history, which can be seen on error printing.

Displaying an Error

For concise logging use the toString method.

console.log(exampleError.toString());

/*
  Huds0nError - EXAMPLE_ERROR (MEDIUM - HANDLED)
*/

For detailed information use the print method.

console.log(exampleError.print());

/*
  
  ---------------------------------------------------------------

  Huds0nError - EXAMPLE_ERROR (MEDIUM - HANDLED)
  Info: {
    ...info is stringified here
  }
  HandledInformation: {
    ...if error's handled flag is an object it is stringified here
  }
  UpdateHx: [...array of overwritten error properties with timestamps]
  ...stack trace

  ---------------------------------------------------------------

*/

Transforming an Error

Sometimes may need to convert an error into a Huds0nError, i.e. a catch block. For this, use the static transform method.

try {
  // Some code
} catch (e) {
  const caughtError = Huds0nError.transform(e, errorProps);
}

The transform error converts any type into a Huds0nError. ErrorProps are then merged to create the Huds0nError, with additional information being placed in the info prop. If the error being transformed is already a Huds0nError it is left unchanged with only the info props being merged.

🧑‍🔬 Advanced Usage

Reviving an Error

HudsOnErrors can easily be turned into JSON with the instance method toJSON, then parsed back to a Huds0nError using the static method JSONreviver

const stringifiedError = exampleError.toJSON();

const revivedError = JSON.parse(stringifiedError, Huds0nError.JSONreviver);

📖 Reference

Error Props

PropRequired/(Default)DescriptionType
codeuser defined error codestring or number
handledfalsewhether error has been handleboolean or object
info{}additional informationobject
messageMessage Missinghuman-readable error messagestring
nameHuds0nErrorerror nameuseful for grouping errorsstring
severityseverity of errorHIGH, MEDIUM,LOW, or NONE
stack(Inherited from JS Error)trace of errorstring

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

  • Special thanks to my fiance, Arma, who has been so patient with all my extra-curricular work.
2.0.0-beta1

1 year ago

1.6.0-beta53

2 years ago

1.6.0-beta54

2 years ago

1.6.0-beta60

2 years ago

1.6.0-beta61

2 years ago

1.6.0-beta63

2 years ago

1.6.0-beta46

2 years ago

1.6.0-beta47

2 years ago

1.6.0-beta48

2 years ago

1.6.0-beta49

2 years ago

1.6.0-beta42

2 years ago

1.6.0-beta44

2 years ago

1.6.0-beta45

2 years ago

1.6.0-beta50

2 years ago

1.6.0-beta51

2 years ago

1.6.0-beta52

2 years ago

1.6.0-beta35

2 years ago

1.6.0-beta36

2 years ago

1.6.0-beta37

2 years ago

1.6.0-beta38

2 years ago

1.6.0-beta31

2 years ago

1.6.0-beta40

2 years ago

1.6.0-beta26

2 years ago

1.6.0-beta13

2 years ago

1.5.1-beta3

3 years ago

1.5.1-beta.1

3 years ago

1.5.1-beta.2

3 years ago

1.5.0-beta.21

3 years ago

1.5.0-beta.20

3 years ago

1.5.0-beta.16

3 years ago

1.5.0-beta.15

3 years ago

1.5.0-beta.14

3 years ago

1.5.0-beta.13

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.4-beta.4

3 years ago

1.3.4-beta.3

3 years ago

1.3.4-beta.2

3 years ago

1.3.4-beta.1

3 years ago

1.3.3-beta.7

3 years ago

1.3.3-beta.6

3 years ago

1.3.3-beta.5

3 years ago

1.3.3-beta.3

3 years ago

1.3.3-beta.4

3 years ago

1.3.3-beta.2

3 years ago

1.3.2-beta.8

3 years ago

1.3.2-beta.7

3 years ago

1.3.2-beta.6

3 years ago

1.3.2-beta.5

4 years ago

1.3.2-beta.4

4 years ago

1.3.2-beta.3

4 years ago

1.3.2-beta.1

4 years ago

1.3.1-beta.24

4 years ago

1.3.1-beta.23

4 years ago

1.3.1-beta.21

4 years ago

1.3.1-beta.22

4 years ago

1.3.1-beta.20

4 years ago

1.3.1-beta.16

4 years ago

1.3.1-beta.17

4 years ago

1.3.1-beta.15

4 years ago

1.3.1-beta.11

4 years ago

1.3.1-beta.9

4 years ago

1.3.1-beta.7

4 years ago

1.3.1-beta.6

4 years ago

1.3.0-beta.21

4 years ago

1.3.0-beta.22

4 years ago

1.3.0-beta.20

4 years ago

1.3.0-beta.19

4 years ago

1.3.0-beta.18

4 years ago

1.3.0-beta.17

4 years ago

1.3.0-beta.16

4 years ago

1.3.0-beta.15

4 years ago

1.3.0-beta.12

4 years ago

1.3.0-beta.13

4 years ago

1.3.0-beta.10

4 years ago

1.3.0-beta.7

4 years ago

1.3.0-beta.6

4 years ago

1.3.0-beta.5

4 years ago

1.2.0-beta.20

4 years ago

1.3.0-beta.2

4 years ago

1.3.0-beta.3

4 years ago

1.3.0-beta.4

4 years ago

1.2.0-beta.19

4 years ago

1.2.0-beta.18

4 years ago

1.2.0-beta.17

4 years ago

1.2.0-beta.16

4 years ago

1.2.0-beta.15

4 years ago

1.2.0-beta.12

4 years ago

1.2.0-beta.14

4 years ago

1.2.0-beta.13

4 years ago

1.2.0-beta.9

4 years ago

1.2.0-beta.8

4 years ago

1.2.0-beta.7

4 years ago

1.2.0-beta.6

4 years ago

1.2.0-beta.5

4 years ago

1.2.0-beta.4

4 years ago

1.2.0-beta.3

4 years ago

1.2.0-beta.2

4 years ago

1.3.0-beta.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

0.1.0

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago