You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/06/09 16:32:47 UTC
[2/2] git commit: Add HttpServer.ResponseException for easier 500
responses
Add HttpServer.ResponseException for easier 500 responses
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/f6fd67fe
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/f6fd67fe
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/f6fd67fe
Branch: refs/heads/master
Commit: f6fd67fe863717f29a77a2f6b8716048b16f4604
Parents: 11f6116
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Jun 5 16:20:42 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Jun 9 10:32:27 2014 -0400
----------------------------------------------------------------------
www/cdvah/js/HarnessServer.js | 10 +++++++---
www/cdvah/js/HttpServer.js | 11 ++++++++++-
2 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/f6fd67fe/www/cdvah/js/HarnessServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HarnessServer.js b/www/cdvah/js/HarnessServer.js
index 5cda1db..ef56b02 100644
--- a/www/cdvah/js/HarnessServer.js
+++ b/www/cdvah/js/HarnessServer.js
@@ -60,7 +60,7 @@
function ensureMethodDecorator(method, func) {
return function(req, resp) {
if (req.method != method) {
- return resp.sendTextResponse(405, 'Method Not Allowed\n');
+ throw new HttpServer.ResponseException(405, 'Method Not Allowed');
}
return func(req, resp);
};
@@ -117,7 +117,7 @@
return resp.sendTextResponse(200, '');
});
}
- return resp.sendTextResponse(412, 'No apps available for launch\n');
+ throw new HttpServer.ResponseException(412, 'No apps available for launch');
});
}
@@ -264,6 +264,8 @@
return ResourcesLoader.extractZipFile(tmpZipUrl, tmpDirUrl);
})
.then(function() {
+ // This file looks like:
+ // {"path/within/zip": { "path": "dest/path", "etag": "foo" }}
return ResourcesLoader.readJSONFileContents(tmpDirUrl + 'zipassetmanifest.json');
}, null, function(unzipPercentage) {
app.updatingStatus = unzipPercentage;
@@ -274,10 +276,12 @@
.then(function next() {
var k = keys.shift();
if (k) {
- return importFile(tmpDirUrl + k, k, app, zipAssetManifest[k]['etag'])
+ return importFile(tmpDirUrl + k, zipAssetManifest[k]['path'], app, zipAssetManifest[k]['etag'])
.then(next);
}
});
+ }, function() {
+ throw new HttpServer.ResponseException(400, 'Zip file missing zipassetmanifest.json');
})
.then(function() {
return incrementUpdateStatusAndSendManifest(app, req, resp);
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/f6fd67fe/www/cdvah/js/HttpServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HttpServer.js b/www/cdvah/js/HttpServer.js
index 9a30a28..2d7244c 100644
--- a/www/cdvah/js/HttpServer.js
+++ b/www/cdvah/js/HttpServer.js
@@ -39,6 +39,11 @@
requestData.state = newState;
}
+ function ResponseException(code, /* optional */ responseText) {
+ this.code = code;
+ this.responseText = responseText;
+ }
+
function HttpRequest(requestData) {
this._requestData = requestData;
this.method = requestData.method;
@@ -396,7 +401,10 @@
if (requestData.state < STATE_RESPONSE_STARTED) {
return req.readEntireBody()
.then(function() {
- return resp.sendTextResponse(500, '' + err);
+ if (err instanceof ResponseException) {
+ return resp.sendTextResponse(err.code, (err.responseText || '') + '\n');
+ }
+ return resp.sendTextResponse(500, '' + err + '\n');
});
} else {
return requestData.socket.close();
@@ -488,6 +496,7 @@
return headers;
}
+ HttpServer.ResponseException = ResponseException;
return HttpServer;
}]);
})();