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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/hanami/webconsole/middleware.rb +53 -4
- data/lib/hanami/webconsole/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15195ce21675c8ec34f19b284cee5cc579e5c6be84597b001d1b94b1d82a2ec2
|
4
|
+
data.tar.gz: 5f95ab6f08ae347f39232b9dda00da8683ab2a02246c5c85579234be42411367
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e859dfe40642b574097b5a88a7e788848176c5e444f014fe8e6dbc23841f4f2a4ed38f75318125e378d08411d4bd2bd623bb0b58d46ac22b743f11faf8eed8d1
|
7
|
+
data.tar.gz: bc6944c729cb8547b2e3c4142c313f071143eac20b1374b2d6dcd9f95e2cb14c06d44d750d9197ab73934bf14e99fdf86d596c64cf9101cd9d4822a47328bbc0
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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
|
-
|
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 =
|
73
|
+
BetterErrors.application_root = @config.root.to_s
|
25
74
|
end
|
26
75
|
end
|
27
76
|
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.
|
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-
|
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.
|
81
|
+
rubygems_version: 3.4.21
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Hanami webconsole
|