# typed: false # frozen_string_literal: true class ApplicationController < ActionController::Base include ActionController::MimeResponds rescue_from ActionController::UnknownFormat, with: :not_acceptable before_action :set_request_span_context def set_request_span_context end after_action :set_response_span_context def set_response_span_context OpenTelemetry::Trace.current_span.add_attributes({ OpenTelemetry::SemanticConventions::Trace::HTTP_RESPONSE_CONTENT_LENGTH => response.headers["content-length"] || 0, }) end def no_content head(:no_content) end def okay render( json: { message: "OK", }.to_json, status: :ok, ) end def created render( json: { message: "Created", }.to_json, status: :created, ) end def bad_request render( json: { errors: [ { message: "Bad Request", }, ], }.to_json, status: :bad_request, ) end def forbidden render( json: { errors: [ { message: "Forbidden", }, ], }.to_json, status: :forbidden, ) end def not_acceptable render( json: ::ErrorSerializer.format("Not Acceptable").to_json, status: :not_acceptable, ) end def not_found render( json: ::ErrorSerializer.format("Not Found").to_json, status: :not_found, ) end def service_unavailable(msg) render( json: { errors: [ { message: "Service Unavailable: #{msg}", }, ], }.to_json, status: :service_unavailable, ) end def bad_gateway render( json: { errors: [ { message: "Bad Gateway", }, ], }.to_json, status: :bad_gateway, ) end def internal_server_error render( json: { errors: [ { message: "Internal Server Error", }, ], }.to_json, status: :internal_server_error, ) end end