Class: Hanami::Router::NotAllowedError

Inherits:
Error
  • Object
show all
Defined in:
lib/hanami/extensions/router/errors.rb

Overview

Error raised when a request is made for a route using a HTTP method not allowed on the route.

Raised only when using hanami-router as part of a full Hanami app. When using hanami-router standalone, the behavior for such requests is to return a “Method Not Allowed” response.

Since:

  • 2.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, allowed_methods) ⇒ NotAllowedError

Returns a new instance of NotAllowedError.

Since:

  • 2.1.0



49
50
51
52
53
54
55
# File 'lib/hanami/extensions/router/errors.rb', line 49

def initialize(env, allowed_methods)
  @env = env
  @allowed_methods = allowed_methods

  message = "Only #{allowed_methods.join(', ')} requests are allowed at #{env["PATH_INFO"]}"
  super(message)
end

Instance Attribute Details

#allowed_methodsArray<String> (readonly)

Returns the allowed methods for the route.

Returns:

  • (Array<String>)

    the allowed methods for the route

Since:

  • 2.1.0



47
48
49
# File 'lib/hanami/extensions/router/errors.rb', line 47

def allowed_methods
  @allowed_methods
end

#envHash (readonly)

Returns the Rack environment for the request.

Returns:

  • (Hash)

    the Rack environment for the request

Since:

  • 2.1.0



41
42
43
# File 'lib/hanami/extensions/router/errors.rb', line 41

def env
  @env
end