Module: Respondo::ControllerHelpers
- Defined in:
- lib/respondo/controller_helpers.rb
Overview
Mixed into Rails controllers to provide render_success and render_error.
Success helpers (2xx):
render_success, render_ok, render_created, render_accepted,
render_non_authoritative, render_no_content, render_reset_content,
render_partial_content, render_multi_status, render_already_reported,
render_im_used
Informational helpers (1xx):
render_continue, render_switching_protocols, render_processing,
render_early_hints
Redirect helpers (3xx):
render_multiple_choices, render_moved_permanently, render_found,
render_see_other, render_not_modified, render_temporary_redirect,
render_permanent_redirect
Client error helpers (4xx):
render_bad_request, render_unauthorized, render_payment_required,
render_forbidden, render_not_found, render_method_not_allowed,
render_not_acceptable, render_proxy_auth_required, render_request_timeout,
render_conflict, render_gone, render_length_required,
render_precondition_failed, render_payload_too_large, render_uri_too_long,
render_unsupported_media_type, render_range_not_satisfiable,
render_expectation_failed, render_im_a_teapot, render_misdirected_request,
render_unprocessable, render_locked, render_failed_dependency,
render_too_early, render_upgrade_required, render_precondition_required,
render_too_many_requests, render_request_header_fields_too_large,
render_unavailable_for_legal_reasons
Server error helpers (5xx):
render_server_error, render_not_implemented, render_bad_gateway,
render_service_unavailable, render_gateway_timeout,
render_http_version_not_supported, render_variant_also_negotiates,
render_insufficient_storage, render_loop_detected, render_not_extended,
render_network_authentication_required
Instance Method Summary collapse
-
#render_accepted(data: nil, message: "Request accepted and is being processed", meta: {}, pagination: nil) ⇒ Object
202 Accepted — async jobs, background processing.
-
#render_already_reported(data: nil, message: "Already reported", meta: {}, pagination: nil) ⇒ Object
208 Already Reported (WebDAV) — members already enumerated.
-
#render_bad_gateway(message: "Bad gateway — upstream service error", errors: nil, meta: {}) ⇒ Object
502 Bad Gateway — upstream service failed.
-
#render_bad_request(message: "Bad request", errors: nil, meta: {}) ⇒ Object
400 Bad Request — malformed request, invalid params.
-
#render_conflict(message: "Resource conflict", errors: nil, meta: {}) ⇒ Object
409 Conflict — duplicate record, state conflict.
-
#render_continue(message: "Continue", meta: {}) ⇒ Object
100 Continue.
-
#render_created(data: nil, message: "Created successfully", meta: {}, pagination: nil) ⇒ Object
201 Created.
-
#render_early_hints(message: "Early hints", meta: {}) ⇒ Object
103 Early Hints.
-
#render_expectation_failed(message: "Expectation failed", errors: nil, meta: {}) ⇒ Object
417 Expectation Failed — Expect header cannot be met.
-
#render_failed_dependency(message: "Failed dependency", errors: nil, meta: {}) ⇒ Object
424 Failed Dependency (WebDAV) — previous request failed.
-
#render_forbidden(message: "You do not have permission to perform this action", errors: nil, meta: {}) ⇒ Object
403 Forbidden — authenticated but not authorized.
-
#render_found(message: "Resource temporarily located elsewhere", meta: {}, pagination: nil) ⇒ Object
302 Found (temporary redirect).
-
#render_gateway_timeout(message: "Gateway timeout — upstream service did not respond", errors: nil, meta: {}) ⇒ Object
504 Gateway Timeout — upstream service timed out.
-
#render_gone(message: "Resource no longer available", errors: nil, meta: {}) ⇒ Object
410 Gone — resource permanently deleted.
-
#render_http_version_not_supported(message: "HTTP version not supported", errors: nil, meta: {}) ⇒ Object
505 HTTP Version Not Supported.
-
#render_im_a_teapot(message: "I'm a teapot", errors: nil, meta: {}) ⇒ Object
418 I’m a Teapot — RFC 2324.
-
#render_im_used(data: nil, message: "IM used", meta: {}, pagination: nil) ⇒ Object
226 IM Used — instance manipulations applied.
-
#render_insufficient_storage(message: "Insufficient storage", errors: nil, meta: {}) ⇒ Object
507 Insufficient Storage (WebDAV).
-
#render_length_required(message: "Content-Length header required", errors: nil, meta: {}) ⇒ Object
411 Length Required — Content-Length header missing.
-
#render_locked(message: "Resource is locked", errors: nil, meta: {}) ⇒ Object
423 Locked — resource is locked.
-
#render_loop_detected(message: "Loop detected", errors: nil, meta: {}) ⇒ Object
508 Loop Detected (WebDAV).
-
#render_method_not_allowed(message: "HTTP method not allowed", errors: nil, meta: {}) ⇒ Object
405 Method Not Allowed.
-
#render_misdirected_request(message: "Misdirected request", errors: nil, meta: {}) ⇒ Object
421 Misdirected Request — request sent to wrong server.
-
#render_moved_permanently(message: "Resource has moved permanently", meta: {}, pagination: nil) ⇒ Object
301 Moved Permanently.
-
#render_multi_status(data: nil, message: "Multi-status response", meta: {}, pagination: nil) ⇒ Object
207 Multi-Status (WebDAV) — batch operations with mixed results.
-
#render_multiple_choices(data: nil, message: "Multiple choices available", meta: {}, pagination: nil) ⇒ Object
300 Multiple Choices.
-
#render_network_authentication_required(message: "Network authentication required", errors: nil, meta: {}) ⇒ Object
511 Network Authentication Required — must authenticate to access network.
-
#render_no_content(message: "Deleted successfully", meta: {}, pagination: nil) ⇒ Object
204 No Content — deletions, actions with no response body Note: we still return our standard JSON structure for consistency.
-
#render_non_authoritative(data: nil, message: "Non-authoritative information", meta: {}, pagination: nil) ⇒ Object
203 Non-Authoritative Information — response from a third-party cache/proxy.
-
#render_not_acceptable(message: "Requested format not acceptable", errors: nil, meta: {}) ⇒ Object
406 Not Acceptable — client Accept header can’t be satisfied.
-
#render_not_extended(message: "Not extended", errors: nil, meta: {}) ⇒ Object
510 Not Extended — further extensions needed.
-
#render_not_found(message: "Resource not found", errors: nil, meta: {}) ⇒ Object
404 Not Found.
-
#render_not_implemented(message: "This feature is not yet implemented", errors: nil, meta: {}) ⇒ Object
501 Not Implemented — feature not built yet.
-
#render_not_modified(message: "Resource not modified", meta: {}, pagination: nil) ⇒ Object
304 Not Modified — client cache is still valid.
-
#render_ok(data: nil, message: nil, meta: {}, pagination: nil) ⇒ Object
200 OK — alias for render_success with no pagination (single record).
-
#render_partial_content(data: nil, message: "Partial content returned", meta: {}, pagination: nil) ⇒ Object
206 Partial Content — chunked / range responses.
-
#render_payload_too_large(message: "Payload too large", errors: nil, meta: {}) ⇒ Object
413 Payload Too Large — request body exceeds server limit.
-
#render_payment_required(message: "Payment required to access this resource", errors: nil, meta: {}) ⇒ Object
402 Payment Required — paywalled features.
-
#render_permanent_redirect(message: "Permanent redirect", meta: {}, pagination: nil) ⇒ Object
308 Permanent Redirect — like 301 but method must not change.
-
#render_precondition_failed(message: "Precondition failed", errors: nil, meta: {}) ⇒ Object
412 Precondition Failed — conditional request failed.
-
#render_precondition_required(message: "Precondition required", errors: nil, meta: {}) ⇒ Object
428 Precondition Required — request must be conditional.
-
#render_processing(message: "Processing", meta: {}) ⇒ Object
102 Processing (WebDAV).
-
#render_proxy_auth_required(message: "Proxy authentication required", errors: nil, meta: {}) ⇒ Object
407 Proxy Authentication Required.
-
#render_range_not_satisfiable(message: "Range not satisfiable", errors: nil, meta: {}) ⇒ Object
416 Range Not Satisfiable — Range header cannot be fulfilled.
-
#render_request_header_fields_too_large(message: "Request header fields too large", errors: nil, meta: {}) ⇒ Object
431 Request Header Fields Too Large.
-
#render_request_timeout(message: "Request timed out", errors: nil, meta: {}) ⇒ Object
408 Request Timeout.
-
#render_reset_content(message: "Reset content", meta: {}, pagination: nil) ⇒ Object
205 Reset Content — tell the client to reset the document view.
-
#render_see_other(message: "See other resource", meta: {}, pagination: nil) ⇒ Object
303 See Other — redirect to another URI with GET.
-
#render_server_error(message: "An unexpected error occurred", errors: nil, meta: {}) ⇒ Object
500 Internal Server Error.
-
#render_service_unavailable(message: "Service temporarily unavailable", errors: nil, meta: {}) ⇒ Object
503 Service Unavailable — maintenance, overloaded.
-
#render_switching_protocols(message: "Switching protocols", meta: {}) ⇒ Object
101 Switching Protocols.
-
#render_temporary_redirect(message: "Temporary redirect", meta: {}, pagination: nil) ⇒ Object
307 Temporary Redirect — repeat request with same method to new URL.
-
#render_too_early(message: "Too early", errors: nil, meta: {}) ⇒ Object
425 Too Early — server unwilling to risk processing replayed request.
-
#render_too_many_requests(message: "Too many requests. Please slow down.", errors: nil, meta: {}) ⇒ Object
429 Too Many Requests — rate limiting.
-
#render_unauthorized(message: "Unauthorized", errors: nil, meta: {}) ⇒ Object
401 Unauthorized — not authenticated.
-
#render_unavailable_for_legal_reasons(message: "Unavailable for legal reasons", errors: nil, meta: {}) ⇒ Object
451 Unavailable for Legal Reasons — censored/DMCA etc.
-
#render_unprocessable(message: "Validation failed", errors: nil, meta: {}) ⇒ Object
422 Unprocessable Entity — validation errors (most common for APIs).
-
#render_unsupported_media_type(message: "Unsupported media type", errors: nil, meta: {}) ⇒ Object
415 Unsupported Media Type — wrong Content-Type header.
-
#render_upgrade_required(message: "Upgrade required", errors: nil, meta: {}) ⇒ Object
426 Upgrade Required — client must switch protocols.
-
#render_uri_too_long(message: "URI too long", errors: nil, meta: {}) ⇒ Object
414 URI Too Long — request URI exceeds server limit.
-
#render_variant_also_negotiates(message: "Variant also negotiates", errors: nil, meta: {}) ⇒ Object
506 Variant Also Negotiates — server configuration error.
Instance Method Details
#render_accepted(data: nil, message: "Request accepted and is being processed", meta: {}, pagination: nil) ⇒ Object
202 Accepted — async jobs, background processing
84 85 86 |
# File 'lib/respondo/controller_helpers.rb', line 84 def render_accepted(data: nil, message: "Request accepted and is being processed", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 202, status: :accepted) end |
#render_already_reported(data: nil, message: "Already reported", meta: {}, pagination: nil) ⇒ Object
208 Already Reported (WebDAV) — members already enumerated
115 116 117 |
# File 'lib/respondo/controller_helpers.rb', line 115 def render_already_reported(data: nil, message: "Already reported", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 208, status: :already_reported) end |
#render_bad_gateway(message: "Bad gateway — upstream service error", errors: nil, meta: {}) ⇒ Object
502 Bad Gateway — upstream service failed
328 329 330 |
# File 'lib/respondo/controller_helpers.rb', line 328 def render_bad_gateway(message: "Bad gateway — upstream service error", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 502, status: :bad_gateway) end |
#render_bad_request(message: "Bad request", errors: nil, meta: {}) ⇒ Object
400 Bad Request — malformed request, invalid params
169 170 171 |
# File 'lib/respondo/controller_helpers.rb', line 169 def render_bad_request(message: "Bad request", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 400, status: :bad_request) end |
#render_conflict(message: "Resource conflict", errors: nil, meta: {}) ⇒ Object
409 Conflict — duplicate record, state conflict
214 215 216 |
# File 'lib/respondo/controller_helpers.rb', line 214 def render_conflict(message: "Resource conflict", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 409, status: :conflict) end |
#render_continue(message: "Continue", meta: {}) ⇒ Object
100 Continue
50 51 52 |
# File 'lib/respondo/controller_helpers.rb', line 50 def render_continue(message: "Continue", meta: {}) render_success(data: nil, message: , meta: , code: 100, status: :continue) end |
#render_created(data: nil, message: "Created successfully", meta: {}, pagination: nil) ⇒ Object
201 Created
79 80 81 |
# File 'lib/respondo/controller_helpers.rb', line 79 def render_created(data: nil, message: "Created successfully", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 201, status: :created) end |
#render_early_hints(message: "Early hints", meta: {}) ⇒ Object
103 Early Hints
65 66 67 |
# File 'lib/respondo/controller_helpers.rb', line 65 def render_early_hints(message: "Early hints", meta: {}) render_success(data: nil, message: , meta: , code: 103, status: :early_hints) end |
#render_expectation_failed(message: "Expectation failed", errors: nil, meta: {}) ⇒ Object
417 Expectation Failed — Expect header cannot be met
254 255 256 |
# File 'lib/respondo/controller_helpers.rb', line 254 def render_expectation_failed(message: "Expectation failed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 417, status: :expectation_failed) end |
#render_failed_dependency(message: "Failed dependency", errors: nil, meta: {}) ⇒ Object
424 Failed Dependency (WebDAV) — previous request failed
279 280 281 |
# File 'lib/respondo/controller_helpers.rb', line 279 def render_failed_dependency(message: "Failed dependency", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 424, status: :failed_dependency) end |
#render_forbidden(message: "You do not have permission to perform this action", errors: nil, meta: {}) ⇒ Object
403 Forbidden — authenticated but not authorized
184 185 186 |
# File 'lib/respondo/controller_helpers.rb', line 184 def render_forbidden(message: "You do not have permission to perform this action", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 403, status: :forbidden) end |
#render_found(message: "Resource temporarily located elsewhere", meta: {}, pagination: nil) ⇒ Object
302 Found (temporary redirect)
140 141 142 |
# File 'lib/respondo/controller_helpers.rb', line 140 def render_found(message: "Resource temporarily located elsewhere", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 302, status: :found) end |
#render_gateway_timeout(message: "Gateway timeout — upstream service did not respond", errors: nil, meta: {}) ⇒ Object
504 Gateway Timeout — upstream service timed out
338 339 340 |
# File 'lib/respondo/controller_helpers.rb', line 338 def render_gateway_timeout(message: "Gateway timeout — upstream service did not respond", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 504, status: :gateway_timeout) end |
#render_gone(message: "Resource no longer available", errors: nil, meta: {}) ⇒ Object
410 Gone — resource permanently deleted
219 220 221 |
# File 'lib/respondo/controller_helpers.rb', line 219 def render_gone(message: "Resource no longer available", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 410, status: :gone) end |
#render_http_version_not_supported(message: "HTTP version not supported", errors: nil, meta: {}) ⇒ Object
505 HTTP Version Not Supported
343 344 345 |
# File 'lib/respondo/controller_helpers.rb', line 343 def render_http_version_not_supported(message: "HTTP version not supported", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 505, status: :http_version_not_supported) end |
#render_im_a_teapot(message: "I'm a teapot", errors: nil, meta: {}) ⇒ Object
418 I’m a Teapot — RFC 2324
259 260 261 |
# File 'lib/respondo/controller_helpers.rb', line 259 def render_im_a_teapot(message: "I'm a teapot", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 418, status: :im_a_teapot) end |
#render_im_used(data: nil, message: "IM used", meta: {}, pagination: nil) ⇒ Object
226 IM Used — instance manipulations applied
120 121 122 |
# File 'lib/respondo/controller_helpers.rb', line 120 def render_im_used(data: nil, message: "IM used", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 226, status: :im_used) end |
#render_insufficient_storage(message: "Insufficient storage", errors: nil, meta: {}) ⇒ Object
507 Insufficient Storage (WebDAV)
353 354 355 |
# File 'lib/respondo/controller_helpers.rb', line 353 def render_insufficient_storage(message: "Insufficient storage", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 507, status: :insufficient_storage) end |
#render_length_required(message: "Content-Length header required", errors: nil, meta: {}) ⇒ Object
411 Length Required — Content-Length header missing
224 225 226 |
# File 'lib/respondo/controller_helpers.rb', line 224 def render_length_required(message: "Content-Length header required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 411, status: :length_required) end |
#render_locked(message: "Resource is locked", errors: nil, meta: {}) ⇒ Object
423 Locked — resource is locked
274 275 276 |
# File 'lib/respondo/controller_helpers.rb', line 274 def render_locked(message: "Resource is locked", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 423, status: :locked) end |
#render_loop_detected(message: "Loop detected", errors: nil, meta: {}) ⇒ Object
508 Loop Detected (WebDAV)
358 359 360 |
# File 'lib/respondo/controller_helpers.rb', line 358 def render_loop_detected(message: "Loop detected", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 508, status: :loop_detected) end |
#render_method_not_allowed(message: "HTTP method not allowed", errors: nil, meta: {}) ⇒ Object
405 Method Not Allowed
194 195 196 |
# File 'lib/respondo/controller_helpers.rb', line 194 def render_method_not_allowed(message: "HTTP method not allowed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 405, status: :method_not_allowed) end |
#render_misdirected_request(message: "Misdirected request", errors: nil, meta: {}) ⇒ Object
421 Misdirected Request — request sent to wrong server
264 265 266 |
# File 'lib/respondo/controller_helpers.rb', line 264 def render_misdirected_request(message: "Misdirected request", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 421, status: :misdirected_request) end |
#render_moved_permanently(message: "Resource has moved permanently", meta: {}, pagination: nil) ⇒ Object
301 Moved Permanently
135 136 137 |
# File 'lib/respondo/controller_helpers.rb', line 135 def render_moved_permanently(message: "Resource has moved permanently", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 301, status: :moved_permanently) end |
#render_multi_status(data: nil, message: "Multi-status response", meta: {}, pagination: nil) ⇒ Object
207 Multi-Status (WebDAV) — batch operations with mixed results
110 111 112 |
# File 'lib/respondo/controller_helpers.rb', line 110 def render_multi_status(data: nil, message: "Multi-status response", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 207, status: :multi_status) end |
#render_multiple_choices(data: nil, message: "Multiple choices available", meta: {}, pagination: nil) ⇒ Object
300 Multiple Choices
130 131 132 |
# File 'lib/respondo/controller_helpers.rb', line 130 def render_multiple_choices(data: nil, message: "Multiple choices available", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 300, status: :multiple_choices) end |
#render_network_authentication_required(message: "Network authentication required", errors: nil, meta: {}) ⇒ Object
511 Network Authentication Required — must authenticate to access network
368 369 370 |
# File 'lib/respondo/controller_helpers.rb', line 368 def render_network_authentication_required(message: "Network authentication required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 511, status: :network_authentication_required) end |
#render_no_content(message: "Deleted successfully", meta: {}, pagination: nil) ⇒ Object
204 No Content — deletions, actions with no response body Note: we still return our standard JSON structure for consistency
95 96 97 |
# File 'lib/respondo/controller_helpers.rb', line 95 def render_no_content(message: "Deleted successfully", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 204, status: :no_content) end |
#render_non_authoritative(data: nil, message: "Non-authoritative information", meta: {}, pagination: nil) ⇒ Object
203 Non-Authoritative Information — response from a third-party cache/proxy
89 90 91 |
# File 'lib/respondo/controller_helpers.rb', line 89 def (data: nil, message: "Non-authoritative information", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 203, status: :non_authoritative_information) end |
#render_not_acceptable(message: "Requested format not acceptable", errors: nil, meta: {}) ⇒ Object
406 Not Acceptable — client Accept header can’t be satisfied
199 200 201 |
# File 'lib/respondo/controller_helpers.rb', line 199 def render_not_acceptable(message: "Requested format not acceptable", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 406, status: :not_acceptable) end |
#render_not_extended(message: "Not extended", errors: nil, meta: {}) ⇒ Object
510 Not Extended — further extensions needed
363 364 365 |
# File 'lib/respondo/controller_helpers.rb', line 363 def render_not_extended(message: "Not extended", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 510, status: :not_extended) end |
#render_not_found(message: "Resource not found", errors: nil, meta: {}) ⇒ Object
404 Not Found
189 190 191 |
# File 'lib/respondo/controller_helpers.rb', line 189 def render_not_found(message: "Resource not found", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 404, status: :not_found) end |
#render_not_implemented(message: "This feature is not yet implemented", errors: nil, meta: {}) ⇒ Object
501 Not Implemented — feature not built yet
323 324 325 |
# File 'lib/respondo/controller_helpers.rb', line 323 def render_not_implemented(message: "This feature is not yet implemented", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 501, status: :not_implemented) end |
#render_not_modified(message: "Resource not modified", meta: {}, pagination: nil) ⇒ Object
304 Not Modified — client cache is still valid
150 151 152 |
# File 'lib/respondo/controller_helpers.rb', line 150 def render_not_modified(message: "Resource not modified", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 304, status: :not_modified) end |
#render_ok(data: nil, message: nil, meta: {}, pagination: nil) ⇒ Object
200 OK — alias for render_success with no pagination (single record)
74 75 76 |
# File 'lib/respondo/controller_helpers.rb', line 74 def render_ok(data: nil, message: nil, meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 200, status: :ok) end |
#render_partial_content(data: nil, message: "Partial content returned", meta: {}, pagination: nil) ⇒ Object
206 Partial Content — chunked / range responses
105 106 107 |
# File 'lib/respondo/controller_helpers.rb', line 105 def render_partial_content(data: nil, message: "Partial content returned", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 206, status: :partial_content) end |
#render_payload_too_large(message: "Payload too large", errors: nil, meta: {}) ⇒ Object
413 Payload Too Large — request body exceeds server limit
234 235 236 |
# File 'lib/respondo/controller_helpers.rb', line 234 def render_payload_too_large(message: "Payload too large", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 413, status: :payload_too_large) end |
#render_payment_required(message: "Payment required to access this resource", errors: nil, meta: {}) ⇒ Object
402 Payment Required — paywalled features
179 180 181 |
# File 'lib/respondo/controller_helpers.rb', line 179 def render_payment_required(message: "Payment required to access this resource", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 402, status: :payment_required) end |
#render_permanent_redirect(message: "Permanent redirect", meta: {}, pagination: nil) ⇒ Object
308 Permanent Redirect — like 301 but method must not change
160 161 162 |
# File 'lib/respondo/controller_helpers.rb', line 160 def render_permanent_redirect(message: "Permanent redirect", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 308, status: :permanent_redirect) end |
#render_precondition_failed(message: "Precondition failed", errors: nil, meta: {}) ⇒ Object
412 Precondition Failed — conditional request failed
229 230 231 |
# File 'lib/respondo/controller_helpers.rb', line 229 def render_precondition_failed(message: "Precondition failed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 412, status: :precondition_failed) end |
#render_precondition_required(message: "Precondition required", errors: nil, meta: {}) ⇒ Object
428 Precondition Required — request must be conditional
294 295 296 |
# File 'lib/respondo/controller_helpers.rb', line 294 def render_precondition_required(message: "Precondition required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 428, status: :precondition_required) end |
#render_processing(message: "Processing", meta: {}) ⇒ Object
102 Processing (WebDAV)
60 61 62 |
# File 'lib/respondo/controller_helpers.rb', line 60 def render_processing(message: "Processing", meta: {}) render_success(data: nil, message: , meta: , code: 102, status: :processing) end |
#render_proxy_auth_required(message: "Proxy authentication required", errors: nil, meta: {}) ⇒ Object
407 Proxy Authentication Required
204 205 206 |
# File 'lib/respondo/controller_helpers.rb', line 204 def render_proxy_auth_required(message: "Proxy authentication required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 407, status: :proxy_authentication_required) end |
#render_range_not_satisfiable(message: "Range not satisfiable", errors: nil, meta: {}) ⇒ Object
416 Range Not Satisfiable — Range header cannot be fulfilled
249 250 251 |
# File 'lib/respondo/controller_helpers.rb', line 249 def render_range_not_satisfiable(message: "Range not satisfiable", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 416, status: :range_not_satisfiable) end |
#render_request_header_fields_too_large(message: "Request header fields too large", errors: nil, meta: {}) ⇒ Object
431 Request Header Fields Too Large
304 305 306 |
# File 'lib/respondo/controller_helpers.rb', line 304 def render_request_header_fields_too_large(message: "Request header fields too large", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 431, status: :request_header_fields_too_large) end |
#render_request_timeout(message: "Request timed out", errors: nil, meta: {}) ⇒ Object
408 Request Timeout
209 210 211 |
# File 'lib/respondo/controller_helpers.rb', line 209 def render_request_timeout(message: "Request timed out", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 408, status: :request_timeout) end |
#render_reset_content(message: "Reset content", meta: {}, pagination: nil) ⇒ Object
205 Reset Content — tell the client to reset the document view
100 101 102 |
# File 'lib/respondo/controller_helpers.rb', line 100 def render_reset_content(message: "Reset content", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 205, status: :reset_content) end |
#render_see_other(message: "See other resource", meta: {}, pagination: nil) ⇒ Object
303 See Other — redirect to another URI with GET
145 146 147 |
# File 'lib/respondo/controller_helpers.rb', line 145 def render_see_other(message: "See other resource", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 303, status: :see_other) end |
#render_server_error(message: "An unexpected error occurred", errors: nil, meta: {}) ⇒ Object
500 Internal Server Error
318 319 320 |
# File 'lib/respondo/controller_helpers.rb', line 318 def render_server_error(message: "An unexpected error occurred", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 500, status: :internal_server_error) end |
#render_service_unavailable(message: "Service temporarily unavailable", errors: nil, meta: {}) ⇒ Object
503 Service Unavailable — maintenance, overloaded
333 334 335 |
# File 'lib/respondo/controller_helpers.rb', line 333 def render_service_unavailable(message: "Service temporarily unavailable", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 503, status: :service_unavailable) end |
#render_switching_protocols(message: "Switching protocols", meta: {}) ⇒ Object
101 Switching Protocols
55 56 57 |
# File 'lib/respondo/controller_helpers.rb', line 55 def render_switching_protocols(message: "Switching protocols", meta: {}) render_success(data: nil, message: , meta: , code: 101, status: :switching_protocols) end |
#render_temporary_redirect(message: "Temporary redirect", meta: {}, pagination: nil) ⇒ Object
307 Temporary Redirect — repeat request with same method to new URL
155 156 157 |
# File 'lib/respondo/controller_helpers.rb', line 155 def render_temporary_redirect(message: "Temporary redirect", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 307, status: :temporary_redirect) end |
#render_too_early(message: "Too early", errors: nil, meta: {}) ⇒ Object
425 Too Early — server unwilling to risk processing replayed request
284 285 286 |
# File 'lib/respondo/controller_helpers.rb', line 284 def render_too_early(message: "Too early", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 425, status: :too_early) end |
#render_too_many_requests(message: "Too many requests. Please slow down.", errors: nil, meta: {}) ⇒ Object
429 Too Many Requests — rate limiting
299 300 301 |
# File 'lib/respondo/controller_helpers.rb', line 299 def render_too_many_requests(message: "Too many requests. Please slow down.", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 429, status: :too_many_requests) end |
#render_unauthorized(message: "Unauthorized", errors: nil, meta: {}) ⇒ Object
401 Unauthorized — not authenticated
174 175 176 |
# File 'lib/respondo/controller_helpers.rb', line 174 def (message: "Unauthorized", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 401, status: :unauthorized) end |
#render_unavailable_for_legal_reasons(message: "Unavailable for legal reasons", errors: nil, meta: {}) ⇒ Object
451 Unavailable for Legal Reasons — censored/DMCA etc.
309 310 311 |
# File 'lib/respondo/controller_helpers.rb', line 309 def render_unavailable_for_legal_reasons(message: "Unavailable for legal reasons", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 451, status: :unavailable_for_legal_reasons) end |
#render_unprocessable(message: "Validation failed", errors: nil, meta: {}) ⇒ Object
422 Unprocessable Entity — validation errors (most common for APIs)
269 270 271 |
# File 'lib/respondo/controller_helpers.rb', line 269 def render_unprocessable(message: "Validation failed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 422, status: :unprocessable_content) end |
#render_unsupported_media_type(message: "Unsupported media type", errors: nil, meta: {}) ⇒ Object
415 Unsupported Media Type — wrong Content-Type header
244 245 246 |
# File 'lib/respondo/controller_helpers.rb', line 244 def render_unsupported_media_type(message: "Unsupported media type", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 415, status: :unsupported_media_type) end |
#render_upgrade_required(message: "Upgrade required", errors: nil, meta: {}) ⇒ Object
426 Upgrade Required — client must switch protocols
289 290 291 |
# File 'lib/respondo/controller_helpers.rb', line 289 def render_upgrade_required(message: "Upgrade required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 426, status: :upgrade_required) end |
#render_uri_too_long(message: "URI too long", errors: nil, meta: {}) ⇒ Object
414 URI Too Long — request URI exceeds server limit
239 240 241 |
# File 'lib/respondo/controller_helpers.rb', line 239 def render_uri_too_long(message: "URI too long", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 414, status: :uri_too_long) end |
#render_variant_also_negotiates(message: "Variant also negotiates", errors: nil, meta: {}) ⇒ Object
506 Variant Also Negotiates — server configuration error
348 349 350 |
# File 'lib/respondo/controller_helpers.rb', line 348 def render_variant_also_negotiates(message: "Variant also negotiates", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 506, status: :variant_also_negotiates) end |