superagent
Advanced tools
Comparing version 0.12.0 to 0.12.1
@@ -73,3 +73,2 @@ ;(function(){ | ||
require.resolve = function(path) { | ||
if (path.charAt(0) === '/') path = path.slice(1); | ||
var index = path + '/index.js'; | ||
@@ -187,14 +186,13 @@ | ||
localRequire.resolve = function(path) { | ||
var c = path.charAt(0); | ||
if ('/' == c) return path.slice(1); | ||
if ('.' == c) return require.normalize(p, path); | ||
// resolve deps by returning | ||
// the dep in the nearest "deps" | ||
// directory | ||
var segs = parent.split('/'); | ||
var i = lastIndexOf(segs, 'deps') + 1; | ||
if (!i) i = 0; | ||
path = segs.slice(0, i + 1).join('/') + '/deps/' + path; | ||
return path; | ||
if ('.' != path.charAt(0)) { | ||
var segs = parent.split('/'); | ||
var i = lastIndexOf(segs, 'deps') + 1; | ||
if (!i) i = 0; | ||
path = segs.slice(0, i + 1).join('/') + '/deps/' + path; | ||
return path; | ||
} | ||
return require.normalize(p, path); | ||
}; | ||
@@ -837,6 +835,6 @@ | ||
if (this.aborted) return; | ||
this.aborted = true; | ||
this.xhr.abort(); | ||
this.clearTimeout(); | ||
this.emit('abort'); | ||
this.aborted = true; | ||
this.clearTimeout(); | ||
return this; | ||
@@ -1019,2 +1017,27 @@ }; | ||
/** | ||
* Invoke callback with x-domain error. | ||
* | ||
* @api private | ||
*/ | ||
Request.prototype.crossDomainError = function(){ | ||
var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); | ||
err.crossDomain = true; | ||
this.callback(err); | ||
}; | ||
/** | ||
* Invoke callback with timeout error. | ||
* | ||
* @api private | ||
*/ | ||
Request.prototype.timeoutError = function(){ | ||
var timeout = this._timeout; | ||
var err = new Error('timeout of ' + timeout + 'ms exceeded'); | ||
err.timeout = timeout; | ||
this.callback(err); | ||
}; | ||
/** | ||
* Initiate request, invoking callback `fn(res)` | ||
@@ -1040,3 +1063,8 @@ * with an instanceof `Response`. | ||
xhr.onreadystatechange = function(){ | ||
if (4 == xhr.readyState && 0 != xhr.status) self.emit('end'); | ||
if (4 != xhr.readyState) return; | ||
if (0 == xhr.status) { | ||
if (self.aborted) return self.timeoutError(); | ||
return self.crossDomainError(); | ||
} | ||
self.emit('end'); | ||
}; | ||
@@ -1047,5 +1075,2 @@ | ||
this._timer = setTimeout(function(){ | ||
var err = new Error('timeout of ' + timeout + 'ms exceeded'); | ||
err.timeout = timeout; | ||
self.callback(err); | ||
self.abort(); | ||
@@ -1052,0 +1077,0 @@ }, timeout); |
@@ -5,3 +5,3 @@ { | ||
"description": "awesome http requests", | ||
"version": "0.11.0", | ||
"version": "0.12.1", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "http", |
0.12.1 / 2013-01-10 | ||
================== | ||
* add x-domain error handling | ||
0.12.0 / 2013-01-04 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -449,6 +449,6 @@ | ||
if (this.aborted) return; | ||
this.aborted = true; | ||
this.xhr.abort(); | ||
this.clearTimeout(); | ||
this.emit('abort'); | ||
this.aborted = true; | ||
this.clearTimeout(); | ||
return this; | ||
@@ -631,2 +631,27 @@ }; | ||
/** | ||
* Invoke callback with x-domain error. | ||
* | ||
* @api private | ||
*/ | ||
Request.prototype.crossDomainError = function(){ | ||
var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); | ||
err.crossDomain = true; | ||
this.callback(err); | ||
}; | ||
/** | ||
* Invoke callback with timeout error. | ||
* | ||
* @api private | ||
*/ | ||
Request.prototype.timeoutError = function(){ | ||
var timeout = this._timeout; | ||
var err = new Error('timeout of ' + timeout + 'ms exceeded'); | ||
err.timeout = timeout; | ||
this.callback(err); | ||
}; | ||
/** | ||
* Initiate request, invoking callback `fn(res)` | ||
@@ -652,3 +677,8 @@ * with an instanceof `Response`. | ||
xhr.onreadystatechange = function(){ | ||
if (4 == xhr.readyState && 0 != xhr.status) self.emit('end'); | ||
if (4 != xhr.readyState) return; | ||
if (0 == xhr.status) { | ||
if (self.aborted) return self.timeoutError(); | ||
return self.crossDomainError(); | ||
} | ||
self.emit('end'); | ||
}; | ||
@@ -659,5 +689,2 @@ | ||
this._timer = setTimeout(function(){ | ||
var err = new Error('timeout of ' + timeout + 'ms exceeded'); | ||
err.timeout = timeout; | ||
self.callback(err); | ||
self.abort(); | ||
@@ -664,0 +691,0 @@ }, timeout); |
{ | ||
"name": "superagent", | ||
"version": "0.12.0", | ||
"version": "0.12.1", | ||
"description": "elegant & feature rich browser / node HTTP with a fluent API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
94122
3233