Sha256: 24c848ad1de45a53bab785e6b6c7ae57d72ceb03399f523d8df1d70e889ab621

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require "modern/errors/error"

module Modern
  module Errors
    class WebError < Modern::Errors::Error
      def status
        raise "#{self.class.name}#status must be implemented."
      end
    end

    class BadRequestError < WebError
      def initialize(msg = "Bad request")
        super(msg)
      end

      def status
        400
      end
    end

    class UnauthorizedError < WebError
      def initialize(msg = "Unauthorized")
        super(msg)
      end

      def status
        401
      end
    end

    class ForbiddenError < WebError
      def initialize(msg = "Forbidden")
        super(msg)
      end

      def status
        403
      end
    end

    class NotFoundError < WebError
      def initialize(msg = "Not found")
        super(msg)
      end

      def status
        404
      end
    end

    class NotAcceptableError < WebError
      def initialize(msg = "Not acceptable (no servable content types in Accept header)")
        super(msg)
      end

      def status
        406
      end
    end

    class UnsupportedMediaTypeError < WebError
      def initialize(msg = "Unrecognized request Content-Type.")
        super(msg)
      end

      def status
        415
      end
    end

    class UnprocessableEntity < WebError
      def initialize(msg = "Recognized content-type of body, but could not parse it.")
        super(msg)
      end

      def status
        422
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
modern-0.5.0 lib/modern/errors/web_errors.rb
modern-0.4.6 lib/modern/errors/web_errors.rb
modern-0.4.5 lib/modern/errors/web_errors.rb
modern-0.4.4 lib/modern/errors/web_errors.rb
modern-0.4.3 lib/modern/errors/web_errors.rb
modern-0.4.2 lib/modern/errors/web_errors.rb