Skip to content
This repository was archived by the owner on Sep 28, 2024. It is now read-only.

Latest commit

 

History

History
72 lines (50 loc) · 1.29 KB

File metadata and controls

72 lines (50 loc) · 1.29 KB

Elefrant Custom Errors

wercker status

Dependency Status

Extend elefrant errors and create your own type of errors.

Install

$ elefrant install elefrant-custom-errors

Usage

Activate the component.

Create your own type of error. Add the new type in lib/errors.js from the component folder.

function MyNewError(message) {
	restify.RestError.call(this, {
		restCode: 'MyNewError',
		statusCode: 418,
		message: message,
		constructorOpt: MyNewError
	});
}
registerError(restify, 'RestError', MyNewError, 'MyNewError');

Extra

###Orm

Format ORM errors and validation.

Add to models a new attribute validationMessages:

...

attributes: {
		name: {
			type: 'string',
			required: true,
			unique: true,
			index: true
		}
	},

...

validationMessages : {
    name: {
        required: 'Name is required',
    }
}
...

And then usage in controller:

next(new restify.OrmError(error, MyModel.validationMessages));

```

## License

MIT © [Elefrant](http://elefrant.com/#/license)