diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-14 04:42:58 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-14 04:42:58 -0400 |
commit | cf34c28f84b9c47bdd03cf8011a5c40495c2b289 (patch) | |
tree | f2189ce8ecd5ac27e04152bbe0e2a766c50421cc /src/guff/handlers | |
parent | cf90fa002afec60e2c057348de24ca1d8bcbaaa4 (diff) | |
download | old-guff-cf34c28f84b9c47bdd03cf8011a5c40495c2b289.tar.bz2 old-guff-cf34c28f84b9c47bdd03cf8011a5c40495c2b289.zip |
send error status code on api error
Diffstat (limited to 'src/guff/handlers')
-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 |