diff options
-rw-r--r-- | src/guff/handlers/api.cr | 11 |
1 files changed, 8 insertions, 3 deletions
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 |