Method: Hoodoo::Errors#add_precompiled_error
- Defined in:
- lib/hoodoo/errors/errors.rb
#add_precompiled_error(code, message, reference, http_status = 500) ⇒ Object
Add a precompiled error to the error collection. Pass error code, error message and reference data directly.
In most cases you should be calling #add_error instead, NOT here.
No validation is performed. You should only really call here if storing an error / errors from another, trusted source with assumed validity (e.g. another service called remotely with errors in the JSON response). It’s possible to store invalid error data using this call, which means counter-to-documentation results could be returned to API clients. That is Very Bad.
Pass optionally the HTTP status code to use if this happens to be the first stored error. If this is omitted, 500 is kept as the default.
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/hoodoo/errors/errors.rb', line 178 def add_precompiled_error( code, , reference, http_status = 500 ) @http_status_code = http_status.to_i if @errors.empty? error = { 'code' => code, 'message' => } error[ 'reference' ] = reference unless reference.nil? || reference.empty? @errors << error end |