From cf34c28f84b9c47bdd03cf8011a5c40495c2b289 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 14 Mar 2016 04:42:58 -0400 Subject: send error status code on api error --- src/guff/handlers/api.cr | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/guff/handlers/api.cr b/src/guff/handlers/api.cr index eab0383..4401f75 100644 --- a/src/guff/handlers/api.cr +++ b/src/guff/handlers/api.cr @@ -80,8 +80,8 @@ class Guff::Handlers::APIHandler < Guff::Handler namespace : String, method : String ) - # set response type - context.response.content_type = get_content_type + # default to success + ok = true # method call json = begin @@ -132,6 +132,9 @@ class Guff::Handlers::APIHandler < Guff::Handler ], }) rescue e + # set error + ok = false + # log backtrace # FIXME puts e.inspect_with_backtrace @@ -140,7 +143,9 @@ class Guff::Handlers::APIHandler < Guff::Handler { "error": e.to_s }.to_json end - # send body + # send type, code, and body + context.response.content_type = get_content_type + context.response.status_code = ok ? 200 : 400 context.response << json end -- cgit v1.2.3