superagent
Advanced tools
Comparing version 0.14.9 to 0.15.0
@@ -5,3 +5,3 @@ { | ||
"description": "awesome http requests", | ||
"version": "0.14.9", | ||
"version": "0.15.0", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "http", |
0.15.0 / 2013-06-25 | ||
================== | ||
* make `Response#toError()` have a more meaningful `message` | ||
0.14.9 / 2013-06-15 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -291,12 +291,13 @@ | ||
function Response(xhr, options) { | ||
function Response(req, options) { | ||
options = options || {}; | ||
this.xhr = xhr; | ||
this.text = xhr.responseText; | ||
this.setStatusProperties(xhr.status); | ||
this.header = this.headers = parseHeader(xhr.getAllResponseHeaders()); | ||
this.req = req; | ||
this.xhr = this.req.xhr; | ||
this.text = this.xhr.responseText; | ||
this.setStatusProperties(this.xhr.status); | ||
this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); | ||
// getAllResponseHeaders sometimes falsely returns "" for CORS requests, but | ||
// getResponseHeader still works. so we get content-type even if getting | ||
// other headers fails. | ||
this.header['content-type'] = xhr.getResponseHeader('content-type'); | ||
this.header['content-type'] = this.xhr.getResponseHeader('content-type'); | ||
this.setHeaderProperties(this.header); | ||
@@ -413,5 +414,12 @@ this.body = this.parseBody(this.text); | ||
Response.prototype.toError = function(){ | ||
var msg = 'got ' + this.status + ' response'; | ||
var req = this.req; | ||
var method = req.method; | ||
var path = req.path; | ||
var msg = 'cannot ' + method + ' ' + path + ' (' + this.status + ')'; | ||
var err = new Error(msg); | ||
err.status = this.status; | ||
err.method = method; | ||
err.path = path; | ||
return err; | ||
@@ -443,3 +451,3 @@ }; | ||
this.on('end', function(){ | ||
var res = new Response(self.xhr); | ||
var res = new Response(self); | ||
if ('HEAD' == method) res.text = null; | ||
@@ -446,0 +454,0 @@ self.callback(null, res); |
@@ -99,5 +99,12 @@ | ||
Response.prototype.toError = function(){ | ||
var msg = 'got ' + this.status + ' response'; | ||
var req = this.req; | ||
var method = req.method; | ||
var path = req.path; | ||
var msg = 'cannot ' + method + ' ' + path + ' (' + this.status + ')'; | ||
var err = new Error(msg); | ||
err.status = this.status; | ||
err.method = method; | ||
err.path = path; | ||
return err; | ||
@@ -104,0 +111,0 @@ }; |
{ | ||
"name": "superagent", | ||
"version": "0.14.9", | ||
"version": "0.15.0", | ||
"description": "elegant & feature rich browser / node HTTP with a fluent API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
104901
3563