UNPKG

899 Btext/coffeescriptView Raw
1exports.types = {}
2exports.types.Redirect = class Redirect
3 constructor: (@location, @code=302, @message) ->
4 @message ?= "Redirecting to #{@location}"
5
6exports.handlers =
7 Redirect: (err, req, res, next) ->
8 res.setHeader 'Location', err.location
9 res.statusCode = err.code
10 res.end err.message
11
12exports.types.NoResponseData = ->
13 @message = "Response data is undefined"
14 @code = 500
15 Error.captureStackTrace @, exports.types.NoResponseData
16
17exports.types.InvalidParameter = (type, thing) ->
18 @message = "Bad Request: invalid #{type} #{thing}"
19 @code = 422
20 Error.captureStackTrace @, exports.types.InvalidParameter
21
22exports.types.NotFound = (type, value) ->
23 @code = 404
24 if type? and value?
25 @message = "#{type} '#{value}' not found"
26 else if type?
27 @message = "#{type} not found"
28 else
29 @message = "Not found"
30 Error.captureStackTrace @, exports.types.NotFound