Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itai-codefresh committed Jul 30, 2016
1 parent 0936a58 commit d2467b3
Showing 1 changed file with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[![Coverage Status](https://coveralls.io/repos/github/codefresh-io/cf-errors/badge.svg?branch=develop)](https://coveralls.io/github/codefresh-io/cf-errors?branch=develop)

# Codefresh erroring library
This library is a wrapper of Verror library that adds additional beheaviour dedicated for our use.
# Extensible error library
This module was written with inspiration taken from verror module.
This library supports a fully extensible error objects.

## Basic Usage - creating an error
### Creating an error
```javascript
var CFError = require('cf-errors');
var ErrorTypes = CFError.errorTypes;
Expand All @@ -16,7 +17,7 @@ var error = new CFError(
);
```

## Advanced Usage - extending an already existing error
### extending an already existing error
```javascript
var extendedError = new CFError(
{
Expand All @@ -27,6 +28,63 @@ var extendedError = new CFError(
);
```

### Predefine Error Types
All http errors are already provided.
All node.js core errors are already provided.

### Extending with your own errors
In order to load your own errors you need to load them.
```javascript
var errors = [
{
name: "YourOwnError,
message: "default message,
field: "value
},
{
name: "YourOwnError1,
message: "default message,
field: "value
}
]
CFErrors.loadErrors(errors);
```
From this point these errors will be available to use.
```javascript
var error = new CFError(
{
type: ErrorType.YourOwnError,
message: `will override default message`,
cause: error
}
);
```
Every field declared in the object will be also accessible
```javascript
console.log(error.field);
```

### Printing the stack
will print the stack of all previous errors too
```javascript
console.log(extendedError.stack);
```
### toString()
will print a the whole chain of errors

### Adding extra information to the error
When constructing an error you can pass an additional field named 'extra' which can hold additional information releated to the current context. this information will be printed as part of the stack or the toString method.
```javascript
var error = new CFError(
{
type: ErrorType.YourOwnError,
message: `will override default message`,
cause: error,
extra: {extraField: "value"}
}
);
```

### Inheriting the previous error type
In order to be able to extend the previous error with more data without affecting the type of the error is possible using the Inherited error type
```javascript
Expand Down

0 comments on commit d2467b3

Please sign in to comment.