class Shamu::JsonApi::ErrorBuilder
Build an error response object.
Attributes
output[R]
Public Class Methods
new()
click to toggle source
# File lib/shamu/json_api/error_builder.rb, line 9 def initialize @output = {} end
Public Instance Methods
code( code )
click to toggle source
Set an application specific error code. @return [self]
# File lib/shamu/json_api/error_builder.rb, line 46 def code( code ) output[:code] = code.to_s self end
compile()
click to toggle source
@return [Hash] the results output as JSON safe hash.
# File lib/shamu/json_api/error_builder.rb, line 83 def compile output end
detail( message )
click to toggle source
@return [String] message details about the error. @return [self]
# File lib/shamu/json_api/error_builder.rb, line 60 def detail( message ) output[:detail] = message self end
exception( exception )
click to toggle source
Summarize an exception as an error. @param [Exception] exception @return [self]
# File lib/shamu/json_api/error_builder.rb, line 26 def exception( exception ) name = exception.class.name.demodulize.gsub( /Error$/, "" ) code name.underscore title name.titleize detail exception.message self end
http_status( status )
click to toggle source
Set an HTTP status code related to the error. @param [Symbol,Integer] status code. @return [self]
# File lib/shamu/json_api/error_builder.rb, line 38 def http_status( status ) status = ::Rack::Utils.status_code( status ) if status.is_a? Symbol output[:status] = status.to_s self end
id( id )
click to toggle source
@param [String] id unique id for this occurrence of the error. @return [self]
# File lib/shamu/json_api/error_builder.rb, line 18 def id( id ) output[:id] = id self end
parameter( name )
click to toggle source
The name of the parameter that caused the error. @return [self]
# File lib/shamu/json_api/error_builder.rb, line 76 def parameter( name ) output[:source] ||= {} output[:source][:parameter] = name self end
pointer( pointer )
click to toggle source
JSON pointer to the associated document in the request that was the source of the pointer. @return [self]
# File lib/shamu/json_api/error_builder.rb, line 68 def pointer( pointer ) output[:source] ||= {} output[:source][:pointer] = pointer self end
title( title )
click to toggle source
Set a short human readable title of the error. @return [self]
# File lib/shamu/json_api/error_builder.rb, line 53 def title( title ) output[:title] = title.to_s self end