Sha256: 82615040a0072095b7987c57ec6931d35d83c6441b552d8fdf762fa75374553e

Contents?: true

Size: 1.25 KB

Versions: 31

Compression:

Stored size: 1.25 KB

Contents

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)
        if @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

  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

31 entries across 31 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.17 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.16 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.15 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.14 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.13 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.12 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.11 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.10 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.9 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.8 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.7 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.6 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.5 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.4 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.3 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.2 lib/praxis/responses/internal_server_error.rb
praxis-2.0.pre.1 lib/praxis/responses/internal_server_error.rb
praxis-0.21 lib/praxis/responses/internal_server_error.rb
praxis-0.20.1 lib/praxis/responses/internal_server_error.rb