module.exports = errors = require 'errors'
The bluebird Promise can catch error by the error type. So we define some special error here.
api.variant sku: '0'
.then (v) ->
console.log v.price
.catch (NotFoundError, err) ->
console.error 'are you sure you provide a right sku?'
.catch (AuthError, err) ->
console.error 'oh! we need key!'
.catch (Http500Error, err) ->
console.error 'wish tired.'
module.exports = errors = require 'errors'
ParamInvalidError
Raise when you provide some invalid param. eg. get order id ‘0’.
Wish is only check a little param. product id ‘0’ will return not found error.
errors.create
name: 'ParamInvalidError'
code: 1000
errors.create
name: 'ParamMissingError'
defaultMessage: 'Required Param Missing'
code: 1001
errors.create
name: 'NotFoundError'
code: 1004
errors.create
name: 'AuthError'
defaultMessage: 'Unauthorized Request'
code: 4000
errors.create
name: 'ServerError'
defaultMessage: 'Server Return Unknown Contest.'
defaultExplanation: 'Maybe server is maintaining.'
code: 911
Find and return special wish error by code.
errors.wish = (body) ->
{ code } = body
FoundError = errors.find code
delete body.code
new FoundError body
Find and return special http error by status code.
errors.http = (code) ->
HttpError = errors.find code
new HttpError