handle-xhr-error
emit error when encountering an xhr error
Last updated 4 years ago by lrlna .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install handle-xhr-error 
SYNC missed versions from official npm registry.

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')
})

API

handleXHRError(data, error, emitter [,cb])

  • data: data to pass on to the error message
  • error.err: error to emit
  • error.statusCode: error status code
  • emitter.emitter: an instance of an emitter you're using
  • emitter.namespace: namespace used for the emitter, e.g. user or login
  • cb: optional callback to pass the error obj back to

Related Content:

  • xhr -- a small wrapper for xhr requests
  • nanobus -- a tiny message bus

License

MIT

Current Tags

  • 2.0.0                                ...           latest (4 years ago)

2 Versions

  • 2.0.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |