hanami-webconsole 2.1.0.beta1 → 2.1.0.rc1

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: 15195ce21675c8ec34f19b284cee5cc579e5c6be84597b001d1b94b1d82a2ec2
4
+ data.tar.gz: 5f95ab6f08ae347f39232b9dda00da8683ab2a02246c5c85579234be42411367
5
5
  SHA512:
6
- metadata.gz: ff3519fc3582a38da7c2c6f267caf5388c6f0e02ad6b1681e6089e021fc9b668b485aab8cf74eea05a09ab14ff09103e52b7a97a59f7ec51ca6e86fc9a3da59e
7
- data.tar.gz: 8a23351a12fad599ddee2b64e6875191a89f30dc571607a54dfeb5baadf172bf63f3a086da72cb0e7fc812c0a0ee2f9a1edb9e33bfe92a58db1ce24a4d580a54
6
+ metadata.gz: e859dfe40642b574097b5a88a7e788848176c5e444f014fe8e6dbc23841f4f2a4ed38f75318125e378d08411d4bd2bd623bb0b58d46ac22b743f11faf8eed8d1
7
+ data.tar.gz: bc6944c729cb8547b2e3c4142c313f071143eac20b1374b2d6dcd9f95e2cb14c06d44d750d9197ab73934bf14e99fdf86d596c64cf9101cd9d4822a47328bbc0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Hanami::Webconsole
2
2
  Hanami development web console.
3
3
 
4
+ ## v2.1.0.rc1 - 2023-11-02
5
+
6
+ ## v2.1.0.beta2 - 2023-10-04
7
+
8
+ ### Fixed
9
+
10
+ - [Tim Riley] Set correct error codes for Hanami app exceptions
11
+
4
12
  ## v2.1.0.beta1 - 2023-06-29
5
13
 
6
14
  ### 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.rc1"
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.rc1
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-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_errors
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  - !ruby/object:Gem::Version
79
79
  version: 1.3.1
80
80
  requirements: []
81
- rubygems_version: 3.4.13
81
+ rubygems_version: 3.4.21
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: Hanami webconsole