Module: JsonApiable::Renderers
- Included in:
- JsonApiable
- Defined in:
- lib/json_apiable/renderers.rb
Instance Method Summary collapse
- #json_render_errors(json: nil, status: nil) ⇒ Object
- #respond_to_bad_argument(err_msg) ⇒ Object
- #respond_to_capability_error ⇒ Object
- #respond_to_exception_raised(err_msg) ⇒ Object
- #respond_to_forbidden(err_msg = nil) ⇒ Object
- #respond_to_malformed_request(err_msg = nil) ⇒ Object
- #respond_to_not_found(err_msg = nil) ⇒ Object
- #respond_to_unauthorized(err_msg = nil) ⇒ Object
- #respond_to_unprocessable_entity(err_msg = nil) ⇒ Object
- #respond_to_unsupported_media_type ⇒ Object
Instance Method Details
#json_render_errors(json: nil, status: nil) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/json_apiable/renderers.rb', line 50 def json_render_errors(json: nil, status: nil) err_json = json.first if err_json.present? && err_json[:status].blank? status_code = status.is_a?(Symbol) ? Rack::Utils::SYMBOL_TO_STATUS_CODE[status] : status err_json[:status] = status_code.to_s end render json: { errors: json }, status: status end |
#respond_to_bad_argument(err_msg) ⇒ Object
30 31 32 33 |
# File 'lib/json_apiable/renderers.rb', line 30 def respond_to_bad_argument(err_msg) errors = [{ title: 'Invalid Argument', detail: err_msg.to_s }] json_render_errors json: errors, status: :bad_request end |
#respond_to_capability_error ⇒ Object
45 46 47 48 |
# File 'lib/json_apiable/renderers.rb', line 45 def respond_to_capability_error errors = [{ title: 'Capability Error', detail: "Your plan doesn't allow this action" }] json_render_errors json: errors, status: :forbidden end |
#respond_to_exception_raised(err_msg) ⇒ Object
35 36 37 38 |
# File 'lib/json_apiable/renderers.rb', line 35 def respond_to_exception_raised(err_msg) errors = [{ title: 'Invalid Argument', detail: err_msg. }] json_render_errors json: errors, status: :bad_request end |
#respond_to_forbidden(err_msg = nil) ⇒ Object
15 16 17 18 |
# File 'lib/json_apiable/renderers.rb', line 15 def respond_to_forbidden(err_msg = nil) errors = [{ title: 'Forbidden', detail: err_msg.to_s || 'You are not authorized to perform this action' }] json_render_errors json: errors, status: :forbidden end |
#respond_to_malformed_request(err_msg = nil) ⇒ Object
40 41 42 43 |
# File 'lib/json_apiable/renderers.rb', line 40 def respond_to_malformed_request(err_msg = nil) errors = [{ title: 'Malformed Request', detail: err_msg.to_s }] json_render_errors json: errors, status: :bad_request end |
#respond_to_not_found(err_msg = nil) ⇒ Object
25 26 27 28 |
# File 'lib/json_apiable/renderers.rb', line 25 def respond_to_not_found(err_msg = nil) errors = [{ title: 'Not Found', detail: err_msg.to_s || 'Resource not found on the server' }] json_render_errors json: errors, status: :not_found end |
#respond_to_unauthorized(err_msg = nil) ⇒ Object
20 21 22 23 |
# File 'lib/json_apiable/renderers.rb', line 20 def (err_msg = nil) errors = [{ title: 'Unauthorized', detail: err_msg.to_s || 'You have to be authenticated to perform this action' }] json_render_errors json: errors, status: :unauthorized end |
#respond_to_unprocessable_entity(err_msg = nil) ⇒ Object
10 11 12 13 |
# File 'lib/json_apiable/renderers.rb', line 10 def respond_to_unprocessable_entity(err_msg = nil) errors = [{ title: 'Unprocessable', detail: err_msg.to_s }] json_render_errors json: errors, status: :unprocessable_entity end |
#respond_to_unsupported_media_type ⇒ Object
5 6 7 8 |
# File 'lib/json_apiable/renderers.rb', line 5 def respond_to_unsupported_media_type errors = [{ title: 'Unsupported Media Type', detail: 'application/vnd.api+json is expected' }] json_render_errors json: errors, status: :unsupported_media_type end |