Module: Goliath::Rack::Validator
- Included in:
- Params
- Defined in:
- lib/actn/api/goliath/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.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/actn/api/goliath/validator.rb', line 41 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
13 14 15 16 |
# File 'lib/actn/api/goliath/validator.rb', line 13 def validation_error(status_code, msg, headers={}) headers.delete('Content-Length') [status_code, headers, Oj.dump({ERROR => msg})] end |