hanami-webconsole 2.1.0.beta1 → 2.1.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10d922780a71a3529439f8cce8c0bd48bac8d27c5db5633fb3b7749d2fac7bc4
4
- data.tar.gz: f1ef77acb63c493d9b6ffa3305066a3abc9c3b5eea6e3403d73a68013f558027
3
+ metadata.gz: bfd72232a858cb02085d8bc8e1e51db6ad511fc9a98b33f2af6216f1a0872369
4
+ data.tar.gz: 13b031ac4e6380391ce93c03e106c3f6f067547bdff7c6e6aa1a2e0579ac7c4e
5
5
  SHA512:
6
- metadata.gz: ff3519fc3582a38da7c2c6f267caf5388c6f0e02ad6b1681e6089e021fc9b668b485aab8cf74eea05a09ab14ff09103e52b7a97a59f7ec51ca6e86fc9a3da59e
7
- data.tar.gz: 8a23351a12fad599ddee2b64e6875191a89f30dc571607a54dfeb5baadf172bf63f3a086da72cb0e7fc812c0a0ee2f9a1edb9e33bfe92a58db1ce24a4d580a54
6
+ metadata.gz: 85e9b3eea0220d6e8bb2b64bf9ecbb963a85d4a0ff678fe114e4aa622ddaca4395768b54b037c1f791f080aec02e1c6c06f6220e1b156a96c8e246e7100a5e84
7
+ data.tar.gz: cf80acd3bdf343e9acdedafd95292c76a439fb3b44bee86195932601f4ebebd4c54460859ccdf08673742bf869adf02d5042323a73c1ec822db32981ca80768a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Hanami::Webconsole
2
2
  Hanami development web console.
3
3
 
4
+ ## v2.1.0.beta2 - 2023-10-04
5
+
6
+ ### Fixed
7
+
8
+ - [Tim Riley] Set correct error codes for Hanami app exceptions
9
+
4
10
  ## v2.1.0.beta1 - 2023-06-29
5
11
 
6
12
  ### Added
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rack"
4
+
3
5
  module Hanami
4
6
  module Webconsole
5
7
  # @api private
@@ -7,21 +9,68 @@ module Hanami
7
9
  class Middleware
8
10
  # @api private
9
11
  # @since 2.1.0
10
- def initialize(app)
12
+ CAPTURE_EXCEPTION_PROC_KEY = "hanami.webconsole.capture_exception_proc"
13
+ private_constant :CAPTURE_EXCEPTION_PROC_KEY
14
+
15
+ # @see Middleware#call
16
+ #
17
+ # @api private
18
+ # @since 2.1.0
19
+ module BetterErrorsExtension
20
+ # The BetterErrors middleware always returns a 500 status when rescuing an exception
21
+ # (outside of Rails). This is not not always appropriate, such as for a
22
+ # `Hanami::Router::NotFoundError`, which should be a 404.
23
+ #
24
+ # To account for this, gently patch `BetterErrors::Middleware#show_error_page` (which is
25
+ # called only when an exception has been rescued) to pass that rescued exception to a proc
26
+ # we inject into the rack env here in our own middleware. This allows our middleware to know
27
+ # the about exception class and provide the correct status code after BetterErrors is done
28
+ # with its job.
29
+ #
30
+ # @see Webconsole::Middleware#call
31
+ def show_error_page(env, exception = nil)
32
+ if (capture_proc = env[CAPTURE_EXCEPTION_PROC_KEY])
33
+ capture_proc.call(exception)
34
+ end
35
+
36
+ super
37
+ end
38
+ end
39
+ BetterErrors::Middleware.prepend(BetterErrorsExtension)
40
+
41
+ # @api private
42
+ # @since 2.1.0
43
+ def initialize(app, config)
11
44
  @better_errors = BetterErrors::Middleware.new(app)
45
+ @config = config
46
+
12
47
  configure_better_errors
13
48
  end
14
49
 
15
50
  # @api private
16
51
  # @since 2.1.0
17
- def call(...)
18
- @better_errors.call(...)
52
+ def call(env)
53
+ rescued_exception = nil
54
+ env[CAPTURE_EXCEPTION_PROC_KEY] = -> ex { rescued_exception = ex }
55
+
56
+ status, headers, body = @better_errors.call(env)
57
+
58
+ # Replace the BetterErrors status with a properly configured one for the Hanami app
59
+ if rescued_exception
60
+ status = Rack::Utils.status_code(
61
+ @config.render_error_responses[rescued_exception.class.name]
62
+ )
63
+ end
64
+
65
+ [status, headers, body]
19
66
  end
20
67
 
21
68
  private
22
69
 
70
+ # @api private
71
+ # @since 2.1.0
23
72
  def configure_better_errors
24
- BetterErrors.application_root = Hanami.app.root.to_s
73
+ BetterErrors.application_root = @config.root.to_s
25
74
  end
26
75
  end
27
76
  end
@@ -3,6 +3,6 @@
3
3
  module Hanami
4
4
  module Webconsole
5
5
  # @since 0.1.0
6
- VERSION = "2.1.0.beta1"
6
+ VERSION = "2.1.0.beta2"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-webconsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta1
4
+ version: 2.1.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-29 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_errors