Sha256: 949295f92d838a574938e5e64ddb50fe5a75841a028c0c084aed409a74fdcb60

Contents?: true

Size: 1.25 KB

Versions: 23

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Praxis
  module Responses
    # A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
    class InternalServerError < Praxis::Response
      self.status = 500
      attr_accessor :error

      def initialize(error: nil, **opts)
        super(**opts)
        @headers['Content-Type'] = 'application/json' # TODO: might want an error mediatype
        @error = error
      end

      def format!(exception = @error)
        return unless @error

        if Application.instance.config.praxis.show_exceptions == true
          msg = {
            name: exception.class.name,
            message: exception.message,
            backtrace: exception.backtrace
          }
          msg[:cause] = format!(exception.cause) if exception.cause
        else
          msg = { name: 'InternalServerError', message: 'Something bad happened.' }
        end

        @body = msg
      end
    end
  end

  ApiDefinition.define do |api|
    api.response_template :internal_server_error do
      description 'A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.'
      status 500
      media_type 'application/json'
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.40 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.39 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.38 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.37 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.36 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.35 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.34 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.33 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.32 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.31 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.30 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.29 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.28 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.27 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.26 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.25 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.24 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.23 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.22 lib/praxis/responses/internal_server_error.rb