class Ant::Server::Format
See Exceptions
module, since this is based on the exceptions too. This will wrap a json object into a standard format, where the response will contain some metadata about the status of the request
Constants
- INTERNAL_SERVER_ERROR_CODE
- INTERNAL_SERVER_ERROR_MESSAGE
Public Instance Methods
error(response)
click to toggle source
an error found while resolving the request.
# File lib/ant/server/format.rb, line 27 def error(response) error_format(:error, response.code, response.message, response.data) end
error_format(level, code, message, data)
click to toggle source
helper to sumarize fatal and error status
# File lib/ant/server/format.rb, line 40 def error_format(level, code, message, data) { status: level, code: code, message: message, data: data } end
fail(response)
click to toggle source
an error on the request. It gives the details of the error.
# File lib/ant/server/format.rb, line 21 def fail(response) error_format(:fail, response.code, response.message, response.data) end
fatal(_data)
click to toggle source
an unhandled error ocurred during the execution of the request.
# File lib/ant/server/format.rb, line 33 def fatal(_data) error_format(:fatal, INTERNAL_SERVER_ERROR_CODE, INTERNAL_SERVER_ERROR_MESSAGE, {}) end
success(response)
click to toggle source
success means there were no errors during the execution of the request it sends the result in the data field.
# File lib/ant/server/format.rb, line 15 def success(response) { status: :success, data: response.result || response.data } end