mirror of
https://github.com/mastodon/mastodon.git
synced 2026-04-01 07:17:44 -05:00
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Bundler Audit / security (push) Has been cancelled
Crowdin / Upload translations / upload-translations (push) Has been cancelled
CSS Linting / lint (push) Has been cancelled
Haml Linting / lint (push) Has been cancelled
69 lines
1.7 KiB
Ruby
69 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module ErrorResponses
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_content
|
|
rescue_from ActionController::ParameterMissing, Paperclip::AdapterRegistry::NoHandlerError, with: :bad_request
|
|
rescue_from ActionController::RoutingError, ActiveRecord::RecordNotFound, with: :not_found
|
|
rescue_from ActionController::UnknownFormat, with: :not_acceptable
|
|
rescue_from Mastodon::NotPermittedError, with: :forbidden
|
|
rescue_from Mastodon::RaceConditionError, Stoplight::Error::RedLight, ActiveRecord::SerializationFailure, with: :service_unavailable
|
|
rescue_from Mastodon::RateLimitExceededError, with: :too_many_requests
|
|
rescue_from(*Mastodon::HTTP_CONNECTION_ERRORS, with: :internal_server_error)
|
|
|
|
rescue_from Seahorse::Client::NetworkingError do |e|
|
|
Rails.logger.warn "Storage server error: #{e}"
|
|
service_unavailable
|
|
end
|
|
end
|
|
|
|
protected
|
|
|
|
def bad_request
|
|
respond_with_error(400)
|
|
end
|
|
|
|
def forbidden
|
|
respond_with_error(403)
|
|
end
|
|
|
|
def gone
|
|
respond_with_error(410)
|
|
end
|
|
|
|
def internal_server_error
|
|
respond_with_error(500)
|
|
end
|
|
|
|
def not_acceptable
|
|
respond_with_error(406)
|
|
end
|
|
|
|
def not_found
|
|
respond_with_error(404)
|
|
end
|
|
|
|
def service_unavailable
|
|
respond_with_error(503)
|
|
end
|
|
|
|
def too_many_requests
|
|
respond_with_error(429)
|
|
end
|
|
|
|
def unprocessable_content
|
|
respond_with_error(422)
|
|
end
|
|
|
|
private
|
|
|
|
def respond_with_error(code)
|
|
respond_to do |format|
|
|
format.any { render "errors/#{code}", layout: 'error', formats: [:html], status: code }
|
|
format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[code] }, status: code }
|
|
end
|
|
end
|
|
end
|