hanami-webconsole 2.1.0.beta1 → 2.1.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/hanami/webconsole/middleware.rb +53 -4
- data/lib/hanami/webconsole/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfd72232a858cb02085d8bc8e1e51db6ad511fc9a98b33f2af6216f1a0872369
|
4
|
+
data.tar.gz: 13b031ac4e6380391ce93c03e106c3f6f067547bdff7c6e6aa1a2e0579ac7c4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85e9b3eea0220d6e8bb2b64bf9ecbb963a85d4a0ff678fe114e4aa622ddaca4395768b54b037c1f791f080aec02e1c6c06f6220e1b156a96c8e246e7100a5e84
|
7
|
+
data.tar.gz: cf80acd3bdf343e9acdedafd95292c76a439fb3b44bee86195932601f4ebebd4c54460859ccdf08673742bf869adf02d5042323a73c1ec822db32981ca80768a
|
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.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-
|
11
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: better_errors
|