From 580550637208b56e360971712ece51fbb9971da5 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Mon, 25 Jul 2016 16:57:44 -0400 Subject: [PATCH] Return 404s automatically when our response is null --- src/main/java/net/frozenorb/apiv3/APIv3.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index e131a0b..7774d73 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -425,8 +425,14 @@ public final class APIv3 extends AbstractVerticle { public static void respondJson(RoutingContext ctx, int code, Object response) { ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()); - ctx.response().setStatusCode(code); - ctx.response().end(gson.toJson(response)); + + if (response == null) { + ctx.response().setStatusCode(404); + ctx.response().end("{}"); + } else { + ctx.response().setStatusCode(code); + ctx.response().end(gson.toJson(response)); + } } } \ No newline at end of file