Sha256: 4015d1c7381195419bb6084c5af8267de14a44fcff5949e524b04184a2a9388a

Contents?: true

Size: 1.17 KB

Versions: 20

Compression:

Stored size: 1.17 KB

Contents

require "nulogy_graphql_api/graphql_error"

module NulogyGraphqlApi
  module ErrorHandling
    extend ActiveSupport::Concern

    included do
      rescue_from StandardError do |exception|
        render_error(exception)
      end

      rescue_from ActiveRecord::RecordNotFound do
        render_not_found
      end
    end

    private

    def show_detailed_error_information?
      Rails.application.config.consider_all_requests_local
    end

    def render_error(exception)
      error = if show_detailed_error_information?
        NulogyGraphqlApi::GraphQLError.new(exception.message, backtrace: exception.backtrace)
      else
        NulogyGraphqlApi::GraphQLError.new("Something went wrong")
      end

      render json: error.render, status: :internal_server_error
    end

    def render_not_found
      render json: NulogyGraphqlApi::GraphQLError.new("Not Found").render, status: :not_found
    end

    def render_unauthorized
      render json: NulogyGraphqlApi::GraphQLError.new("Unauthorized").render, status: :unauthorized
    end

    def render_timeout
      render json: NulogyGraphqlApi::GraphQLError.new("Request Timeout").render, status: :request_timeout
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nulogy_graphql_api-4.3.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-4.2.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-4.1.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-4.0.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-3.0.1 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-2.2.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-2.1.3 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-2.1.2 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-2.1.1 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-2.1.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-2.0.1 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-2.0.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-1.1.1 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-1.1.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-1.0.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-0.6.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-0.5.3 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-0.5.1 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-0.5.0 lib/nulogy_graphql_api/error_handling.rb
nulogy_graphql_api-0.4.0 lib/nulogy_graphql_api/error_handling.rb