module Moromi::Error::Renderer

Constants

ERROR_TEMPLATES

Public Instance Methods

render_bad_request(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 20
def render_bad_request(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(400, 'Bad Request', exception, options: options, locals: locals)
end
render_conflict(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 36
def render_conflict(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(409, 'Conflict', exception, options: options, locals: locals)
end
render_forbidden(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 28
def render_forbidden(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(403, 'Forbidden', exception, options: options, locals: locals)
end
render_force_update(exception: Moromi::Error::NeedForceUpdate.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 48
def render_force_update(exception: Moromi::Error::NeedForceUpdate.new, options: nil, locals: {})
  render_bad_request(exception: exception, options: options, locals: locals)
end
render_gone(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 40
def render_gone(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(410, 'Gone', exception, options: options, locals: locals)
end
render_internal_server_error(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 52
def render_internal_server_error(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(500, 'Internal Server Error', exception, options: options, locals: locals)
end
render_not_found(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 32
def render_not_found(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(404, 'Not Found', exception, options: options, locals: locals)
end
render_service_unavailable(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 56
def render_service_unavailable(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(503, 'Service Unavailable', exception, options: options, locals: locals)
end
render_too_many_requests(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 44
def render_too_many_requests(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(429, 'Too Many Requests', exception, options: options, locals: locals)
end
render_unauthorized(exception: Moromi::Error::Default.new, options: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 24
def render_unauthorized(exception: Moromi::Error::Default.new, options: nil, locals: {})
  render_error(401, 'Unauthorized', exception, options: options, locals: locals)
end

Private Instance Methods

render_error(status, title, exception, options: nil, template_path: nil, locals: {}) click to toggle source
# File lib/moromi/error/renderer.rb, line 62
def render_error(status, title, exception, options: nil, template_path: nil, locals: {})
  template_path ||= self.class::default_moromi_error_template_path
  options = options || self.class::default_moromi_error_renderer_options
  e = Moromi::Error::Default.make(exception)

  self.class::moromi_error_logger.write(self, status, title, exception, options, locals)

  options = {status: status}.merge(options)
  locals = {status: status, title: title, exception: e}.merge(locals)

  render_block = -> {
    render template_path, **options, locals: locals
  }

  respond_to do |format|
    format.html &render_block
    format.json &render_block
  end
rescue ActionController::UnknownFormat
  render status: 406, body: "Not Acceptable"
end