Skip to content

Commit 1102186

Browse files
author
hideki
committed
Fixed response body to include status code for error case
1 parent 37980ef commit 1102186

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/main/java/com/couchbase/lite/router/Router.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,8 @@ public void start() {
548548
// Send myself a message based on the components:
549549
Status status = null;
550550
try {
551-
552551
Method m = Router.class.getMethod(message, Database.class, String.class, String.class);
553552
status = (Status) m.invoke(this, db, docID, attachmentName);
554-
555553
} catch (NoSuchMethodException msme) {
556554
try {
557555
String errorMessage = String.format("Router unable to route request to %s", message);
@@ -565,22 +563,25 @@ public void start() {
565563
} catch (Exception e) {
566564
//default status is internal server error
567565
Log.e(Log.TAG_ROUTER, "Router attempted do_UNKNWON fallback, but that threw an exception", e);
566+
status = new Status(Status.NOT_FOUND);
568567
Map<String, Object> result = new HashMap<String, Object>();
569-
result.put("error", "not_found");
568+
result.put("status", status.getHTTPCode());
569+
result.put("error", status.getHTTPMessage());
570570
result.put("reason", "Router unable to route request");
571571
connection.setResponseBody(new Body(result));
572-
status = new Status(Status.NOT_FOUND);
573572
}
574573
} catch (Exception e) {
575574
String errorMessage = "Router unable to route request to " + message;
576575
Log.e(Log.TAG_ROUTER, errorMessage, e);
577576
Map<String, Object> result = new HashMap<String, Object>();
578577
if (e.getCause() != null && e.getCause() instanceof CouchbaseLiteException) {
579578
status = ((CouchbaseLiteException) e.getCause()).getCBLStatus();
579+
result.put("status", status.getHTTPCode());
580580
result.put("error", status.getHTTPMessage());
581581
result.put("reason", errorMessage + e.getCause().toString());
582582
} else {
583583
status = new Status(Status.NOT_FOUND);
584+
result.put("status", status.getHTTPCode());
584585
result.put("error", status.getHTTPMessage());
585586
result.put("reason", errorMessage + e.toString());
586587
}

0 commit comments

Comments
 (0)