Sha256: 75bcca72f703db06b7c1dc5955b1fd864a5f5fbb78f12708fea6da1fe5c2854a

Contents?: true

Size: 847 Bytes

Versions: 6

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

module Railsful
  # The base error for this gem.
  class Error < StandardError
    attr_reader :detail, :status

    # Initializer.
    #
    # @param detail [String] The detailed message.
    # @param status [Integer] The status code.
    def initialize(detail = nil, status = 400)
      @detail = detail
      @status = status
    end

    # Format the error as jsonapi wants it to.
    #
    # @return [Hash]
    def as_json(_options = nil)
      {
        errors: [
          {
            status: status,
            title: self.class.name.demodulize.underscore,
            detail: detail
          }
        ]
      }
    end
  end

  # The error that is raised when pagination fails.
  class PaginationError < Error; end
  # The error that is raised when sorting fails.
  class SortingError < Error; end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
railsful-0.3.0 lib/railsful/exceptions.rb
railsful-0.2.0 lib/railsful/exceptions.rb
railsful-0.1.3 lib/railsful/exceptions.rb
railsful-0.1.2 lib/railsful/exceptions.rb
railsful-0.1.1 lib/railsful/exceptions.rb
railsful-0.1.0 lib/railsful/exceptions.rb