Eric Foster d5378345de connection between front end and database | 6 年前 | |
---|---|---|
.. | ||
test | 6 年前 | |
.istanbul.yml | 6 年前 | |
.npmignore | 6 年前 | |
MIGRATION.md | 6 年前 | |
README.md | 6 年前 | |
docs.mli | 6 年前 | |
io.js | 6 年前 | |
option.js | 6 年前 | |
package.json | 6 年前 | |
typed.js | 6 年前 | |
validation.js | 6 年前 | |
wrapped.js | 6 年前 |
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