Skip to content

Commit

Permalink
Add loader and better error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
wejendorp committed Apr 16, 2014
1 parent d34bcf0 commit f4c158e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ build: node_modules components $(SRC)
components: component.json
@$(C) install --dev

release: node_modules components
@$(C) build -o release -n angular-superagent
release: node_modules components $(SRC)
@$(C) build
@cat build/build.js loader.js > release/angular-superagent.js

kill:
-@test -e test/pid.txt \
Expand All @@ -44,7 +45,7 @@ test-sauce: build server
@BROWSERS=$(BROWSERS) $(GRAVY) --url $(TEST)

clean:
rm -rf components build
rm -rf components release

.PHONY: clean server test test-browser
.PHONY: release clean server test test-browser
.PHONY: test-sauce test-coverage
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ angular.module('ngSuperagent', ['ng'])
resolve: $q.when
};

var request = this;
this.end(function(err, res) {
if(err) {
agent.emit('error', err);
err.method = request.method;
err.url = request.url;
err = $q.reject(err);
}

Expand Down
3 changes: 3 additions & 0 deletions loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

// Loader for bower releases
require('angular-superagent');
23 changes: 19 additions & 4 deletions release/angular-superagent.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,13 +644,13 @@ Response.prototype.setStatusProperties = function(status){
Response.prototype.toError = function(){
var req = this.req;
var method = req.method;
var path = req.path;
var url = req.url;

var msg = 'cannot ' + method + ' ' + path + ' (' + this.status + ')';
var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')';
var err = new Error(msg);
err.status = this.status;
err.method = method;
err.path = path;
err.url = url;

return err;
};
Expand Down Expand Up @@ -690,6 +690,15 @@ function Request(method, url) {

Emitter(Request.prototype);

/**
* Allow for extension
*/

Request.prototype.use = function(fn) {
fn(this);
return this;
}

/**
* Set timeout to `ms`.
*
Expand Down Expand Up @@ -1071,6 +1080,7 @@ Request.prototype.end = function(fn){
}

// send stuff
this.emit('request', this);
xhr.send(data);
return this;
};
Expand Down Expand Up @@ -1455,9 +1465,12 @@ angular.module('ngSuperagent', ['ng'])
resolve: $q.when
};

var request = this;
this.end(function(err, res) {
if(err) {
agent.emit('error', err);
err.method = request.method;
err.url = request.url;
err = $q.reject(err);
}

Expand Down Expand Up @@ -1541,4 +1554,6 @@ require.alias("visionmedia-superagent/lib/client.js", "visionmedia-superagent/in
require.alias("component-emitter/index.js", "angular-superagent/deps/emitter/index.js");
require.alias("component-emitter/index.js", "emitter/index.js");

require.alias("angular-superagent/index.js", "angular-superagent/index.js");
require.alias("angular-superagent/index.js", "angular-superagent/index.js");
// Loader for bower releases
require('angular-superagent');

0 comments on commit f4c158e

Please sign in to comment.