Eric Foster 35b96bc934 initial commit | 6 gadus atpakaļ | |
---|---|---|
.. | ||
test | 6 gadus atpakaļ | |
.istanbul.yml | 6 gadus atpakaļ | |
.npmignore | 6 gadus atpakaļ | |
MIGRATION.md | 6 gadus atpakaļ | |
README.md | 6 gadus atpakaļ | |
docs.mli | 6 gadus atpakaļ | |
io.js | 6 gadus atpakaļ | |
option.js | 6 gadus atpakaļ | |
package.json | 6 gadus atpakaļ | |
typed.js | 6 gadus atpakaļ | |
validation.js | 6 gadus atpakaļ | |
wrapped.js | 6 gadus atpakaļ |
Custom errors
var TypedError = require("error/typed")
var ServerError = TypedError({
type: 'server.5xx',
message: '{title} server error, status={statusCode}',
title: null,
statusCode: null
});
var ClientError = TypedError({
type: 'client.4xx',
message: '{title} client error, status={statusCode}',
title: null,
statusCode: null
});
var error = ServerError({
title:'some title',
statusCode: 500
});
var error2 = ClientError({
title: 'some title',
statusCode: 404
});
var net = require('net');
var WrappedError = require('error/wrapped');
var ServerListenError = WrappedError({
message: 'server: {origMessage}',
type: 'server.listen-failed',
requestedPort: null,
host: null
});
var server = net.createServer();
server.on('error', function onError(err) {
if (err.code === 'EADDRINUSE') {
throw ServerListenError(err, {
requestedPort: 3000,
host: null
});
} else {
throw err;
}
});
server.listen(3000);
npm install error