Sha256: e18363bfe291bc5c393c267bf1de43288415d6d5f1adb5c29601b3f0e2a67d0f
Contents?: true
Size: 1.13 KB
Versions: 15
Compression:
Stored size: 1.13 KB
Contents
module ApiErrorConcern extend ActiveSupport::Concern included do rescue_from "Exception" do |exception| logger.error exception.message logger.error exception.backtrace.join("\n") respond_api_error(:internal_server_error, message: "server_error", type: exception.class.to_s, detail: exception.message) end rescue_from "ActiveRecord::RecordNotFound" do |exception| respond_api_error(:not_found, message: "record_not_found", detail: exception.message) end rescue_from "ActiveModel::ForbiddenAttributesError" do |exception| respond_api_error(:bad_request, message: "protected_attributes", detail: exception.message) end rescue_from "ActiveRecord::RecordInvalid" do |exception| respond_api_error(:bad_request, message: "invalid_attributes", errors: exception.record.errors) end end def respond_api_error(status, error = {}) render json: error, status: status end end
Version data entries
15 entries across 15 versions & 1 rubygems