Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added context and changed parameter structure to object #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,36 @@ Logs the final object using passed function, Elastic URL or `Debug` library with
const error = new ErrorCustom(message, statusCode, errorCode, baseError, logFunction);
```

* {string} `message`
Error message to set on the Error object
* {string | IConfig} `message`
Error message to set on the Error object, or a config object for all parameters
* {number} `statusCode`
HTTP status code
HTTP status code, optional as it can be passed as part of the config
* {number} `errorCode`
The specific error code as defined in documentation
The specific error code as defined in documentation, optional as it can be passed as part of the config
* {Error} `baseError`
Optional base exception to be included as innerException property
* {Function|string} `logFunction`
Optional function to log the error with. If not supplied, debug library will be used
to log to the console with the tag `error-custom`. If a string is provided that is a
URL, it will be used to send to that URL with ElasticSearch client in Winston format.
* {object} `context`
Optional context information to provide with the error

## IConfig definition
An `Iconfig` object can be apssed instead of individual parameters as below, where the definition are the same as the constructor.
```
export interface IConfig {
message: string;
statusCode: number;
errorCode: number;
baseError?: Error;
logFunction?: string | Function;
context: any;
}
```

## toJSON
The object includes a `toJSON()` override to make all parameters iterable. Note that this returns an object, not a JSON string.

## Environment Variables
Functionality can be modified with various environment variables:
Expand Down
Loading