From f4c158e989cb68031c14f3cf3b7221c7b8f722f9 Mon Sep 17 00:00:00 2001 From: Jacob Wejendorp Date: Wed, 16 Apr 2014 17:25:30 +0200 Subject: [PATCH] Add loader and better error reporting --- Makefile | 9 +++++---- index.js | 3 +++ loader.js | 3 +++ release/angular-superagent.js | 23 +++++++++++++++++++---- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 loader.js diff --git a/Makefile b/Makefile index 8a4e1ee..3aa0c84 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 diff --git a/index.js b/index.js index 4139036..24196b7 100644 --- a/index.js +++ b/index.js @@ -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); } diff --git a/loader.js b/loader.js new file mode 100644 index 0000000..c85f3c0 --- /dev/null +++ b/loader.js @@ -0,0 +1,3 @@ + +// Loader for bower releases +require('angular-superagent'); diff --git a/release/angular-superagent.js b/release/angular-superagent.js index ec35e90..e84be07 100644 --- a/release/angular-superagent.js +++ b/release/angular-superagent.js @@ -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; }; @@ -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`. * @@ -1071,6 +1080,7 @@ Request.prototype.end = function(fn){ } // send stuff + this.emit('request', this); xhr.send(data); return this; }; @@ -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); } @@ -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"); \ No newline at end of file +require.alias("angular-superagent/index.js", "angular-superagent/index.js"); +// Loader for bower releases +require('angular-superagent');