Skip to content

Conversation

weppos
Copy link
Contributor

@weppos weppos commented Jan 16, 2015

When #message is given, it sets the response body with the message.

This is useful in case you need to set a different response for the same HTTP error. For instance, a 403 may be caused by an invalid password, an invalid username, or a bad OAUTH token.

When #message is given, it sets the response body with the message.
@weppos
Copy link
Contributor Author

weppos commented Jan 16, 2015

Real world example, given the following error helper

def error(code, message)
  self.format = :json
  halt(code, { message: message }.to_json)
end

I'd like to be able to perform

def authenticate!
  authentication_context or error(401, I18n.t("api.message_error_authentication_failed"))
end

or to use the helper as a result of an exception handler.

def handle_record_not_found(exception)
  halt(404, { message: exception.message }.to_json)
end

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 141dd97 on weppos:halt-with-message into * on lotus:master*.

@AlfonsoUceda
Copy link
Contributor

👍 looks good

@jodosha jodosha merged commit 141dd97 into hanami:master Jan 19, 2015
jodosha added a commit that referenced this pull request Jan 19, 2015
@jodosha
Copy link
Member

jodosha commented Jan 19, 2015

@weppos Thanks for this PR it looks good, merged 👍

@weppos weppos deleted the halt-with-message branch January 19, 2015 19:16
@jodosha jodosha modified the milestone: v0.3.2 Jan 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants