$ cnpm install handle-xhr-error
A tiny module to handle errors in an xhr request in an emitter based application.
var handleXHRError = require('handle-xhr-error')
var emitter = require('nanobus')()
var xhr = require('xhr')
var opts = {
method: 'PUT',
url: 'user/2',
json: { kitty: cat },
headers: {
'content-type': 'application/json'
}
}
xhr(opts, function (err, res, data) {
if (err || res.statusCode > 299) {
return handleXHRError(data, err, res.statusCode, emitter)
}
emitter.emit('user:message', 'Your password has been updated')
})
user
or login
Copyright 2014 - 2017 © taobao.org |