module Terrain::Errors

Public Instance Methods

association_not_found() click to toggle source
# File lib/terrain/errors.rb, line 33
def association_not_found
  error_response(:association_not_found, 400)
end
error_response(key = :server_error, status = 500, details = nil) click to toggle source
# File lib/terrain/errors.rb, line 18
def error_response(key = :server_error, status = 500, details = nil)
  result = {
    error: {
      key: key,
      message: I18n.t("terrain.errors.#{key}", request: request)
    }
  }

  if details.present?
    result[:error][:details] = details
  end

  render json: result, status: status
end
range_error() click to toggle source
# File lib/terrain/errors.rb, line 57
def range_error
  error_response(:range_error, 416)
end
record_invalid(error) click to toggle source
# File lib/terrain/errors.rb, line 53
def record_invalid(error)
  error_response(:record_invalid, 422, error.record.errors.to_hash)
end
record_not_found() click to toggle source
# File lib/terrain/errors.rb, line 45
def record_not_found
  error_response(:record_not_found, 404)
end
route_not_found() click to toggle source
# File lib/terrain/errors.rb, line 49
def route_not_found
  error_response(:route_not_found, 404)
end
unauthenticated() click to toggle source
# File lib/terrain/errors.rb, line 37
def unauthenticated
  error_response(:unauthenticated, 401)
end
unauthorized() click to toggle source
# File lib/terrain/errors.rb, line 41
def unauthorized
  error_response(:unauthorized, 403)
end