Skip to content

Cross-browser Error object for use with XHR requests

License

Notifications You must be signed in to change notification settings

chrisbuttery/xhrerror

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XhrError

A generic Error object for use when performing XHR requests. XHR component writers are encouraged to use this Error object to signal errors / incomplete requests.

Installation

XhrError is a component.

$ component install matthewp/xhrerror

Usage

XhrError is a tiny object that serves 1 purpose, to signal an error in an XHR requests.

var XhrError = require('xhrerror');

function doAjaxyRequest(url, callback) {

  ...
  // Oops, there was an error.
  var err = new XhrError("Oops, couldn't find that.", 404);
  callback(err);
}

API

XhrError(message, status, request)

Create a new XhrError. Optionally provide a message string, a status code and the full failed request.

XhrError#status

The status code returned from the XHR attempt.

XhrError#message

Inheriting from Error#message, the string message for the error.

XhrError#request

Inheriting from Error#request, the request obj for the error. Access err.req.getAllResponseHeaders().

XhrError#stack

Inheriting from Error#stack, the stack trace from which the XhrError was created.

Dependencies

None.

About

Cross-browser Error object for use with XHR requests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%