Module: Goliath::Rack::Validator
- Defined in:
- lib/grass/goliath/rack/validator.rb
Constant Summary collapse
- ERROR =
'error'
Class Method Summary collapse
-
.safely(env, headers = {}) ⇒ Object
Execute a block of code safely.
- .validation_error(status_code, msg, headers = {}) ⇒ Object
Class Method Details
.safely(env, headers = {}) ⇒ Object
Execute a block of code safely.
If the block raises any exception that derives from Goliath::Validation::Error (see specifically those in goliath/validation/standard_http_errors.rb), it will be turned into the corresponding 4xx response with a corresponding message.
If the block raises any other kind of error, we log it and return a less-communicative 500 response.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/grass/goliath/rack/validator.rb', line 39 def safely(env, headers={}) begin yield rescue Goliath::Validation::Error => e validation_error(e.status_code, e., headers) rescue Exception => e env.logger.error(e.) env.logger.error(e.backtrace.join("\n")) validation_error(500, e., headers) end end |
.validation_error(status_code, msg, headers = {}) ⇒ Object
11 12 13 14 |
# File 'lib/grass/goliath/rack/validator.rb', line 11 def validation_error(status_code, msg, headers={}) headers.delete('Content-Length') [status_code, headers, {ERROR => msg}] end |