1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Make HTTP errors returned from the Aphlict server more specific

Summary: Ref T5651. Currently, the Aphlict server returns either `200 OKAY` or `400 Bad Request`. We could return more specific errors in some cases and this may assist with debugging.

Test Plan:
Sent myself a test notification at `/notification/status/` and saw the Aphlict server process the request (running in debug mode). Also poked around with `curl`:

```
> curl http://localhost:22281/
405 Method Not Allowed

> curl http://localhost:22281/ -d ""
400 Bad Request

> curl http://localhost:22281/foobar/
404 Not Found
```

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5651

Differential Revision: https://secure.phabricator.com/D9967
This commit is contained in:
Joshua Spence 2014-07-18 09:01:46 +10:00
parent 45ea88cec4
commit 41a8837f78
2 changed files with 33 additions and 25 deletions

View file

@ -40,6 +40,8 @@ final class PhabricatorNotificationClient {
private static function postMessage(array $data) { private static function postMessage(array $data) {
$server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri'); $server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
$server_uri = id(new PhutilURI($server_uri))
->setPath('/');
id(new HTTPSFuture($server_uri, json_encode($data))) id(new HTTPSFuture($server_uri, json_encode($data)))
->setMethod('POST') ->setMethod('POST')

View file

@ -163,6 +163,7 @@ var start_time = new Date().getTime();
var receive_server = http.createServer(function(request, response) { var receive_server = http.createServer(function(request, response) {
// Publishing a notification. // Publishing a notification.
if (request.url == '/') {
if (request.method == 'POST') { if (request.method == 'POST') {
var body = ''; var body = '';
@ -185,11 +186,16 @@ var receive_server = http.createServer(function(request, response) {
request.socket.remoteAddress, request.socket.remoteAddress,
err); err);
response.statusCode = 400; response.statusCode = 400;
response.write('400 Bad Request'); response.write('400 Bad Request\n');
} finally { } finally {
response.end(); response.end();
} }
}); });
} else {
response.statusCode = 405;
response.write('405 Method Not Allowed\n');
response.end();
}
} else if (request.url == '/status/') { } else if (request.url == '/status/') {
request.on('data', function() { request.on('data', function() {
// We just ignore the request data, but newer versions of Node don't // We just ignore the request data, but newer versions of Node don't
@ -212,8 +218,8 @@ var receive_server = http.createServer(function(request, response) {
response.end(); response.end();
}); });
} else { } else {
response.statusCode = 400; response.statusCode = 404;
response.write('400 Bad Request'); response.write('404 Not Found\n');
response.end(); response.end();
} }
}).listen(config.admin, config.host); }).listen(config.admin, config.host);