Module: Goliath::Rack::Validator
- Included in:
- API, AsyncMiddleware, BarrierAroundwareFactory, Params, SimpleAroundware, SimpleAroundwareFactory, Types::Base, Goliath::Rack::Validation::Param, Goliath::Rack::Validation::RequestMethod, Goliath::Rack::Validation::RequiredParam, Goliath::Rack::Validation::RequiredValue
- Defined in:
- lib/goliath/rack/validator.rb
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.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/goliath/rack/validator.rb', line 38 def safely(env, headers={}) begin yield rescue Goliath::Validation::Error => e validation_error(e.status_code, e., e.headers.merge(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
10 11 12 13 |
# File 'lib/goliath/rack/validator.rb', line 10 def validation_error(status_code, msg, headers={}) headers.delete('Content-Length') [status_code, headers, {:error => msg}] end |