blacksheep 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/blacksheep.rb +1 -0
- data/lib/blacksheep/action_error.rb +15 -0
- data/lib/blacksheep/action_result.rb +27 -0
- data/lib/blacksheep/decorators/default_error_handler.rb +48 -58
- data/lib/blacksheep/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c49ec47c41acddb7ed3dc1ce015c75d427dfc26107c2bd8687243c7d05d0a6
|
4
|
+
data.tar.gz: 7f45f1fecf5e97585778edc375c225ccff65c668a6f23a8c6b539b4c52b475dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00f30d27444904c1f63c696a8492f5173832cb47797dacfdd8261d77bdfed70ba6b63bb2c58abd08f17ddde071d547598ae354e29f95487dedd64af2874c56eb
|
7
|
+
data.tar.gz: 8e154027acc2c66f1cf5b22968174157eacb11a5fcc06de33eaf4f0bbeed754219646cec79199f919e304c1a312fcd2b3318f3d0961cbb20eda57c28bbf7ba5c
|
data/Gemfile.lock
CHANGED
data/lib/blacksheep.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Blacksheep
|
2
|
+
#
|
3
|
+
# @class Blacksheep::ActionError
|
4
|
+
class ActionError < StandardError
|
5
|
+
attr_reader :identifier, :title
|
6
|
+
|
7
|
+
def initialize(message, title: 'Error', identifier: 'undefined')
|
8
|
+
@identifier = identifier
|
9
|
+
@title = title
|
10
|
+
|
11
|
+
super(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -8,6 +8,33 @@ module Blacksheep
|
|
8
8
|
@status = status
|
9
9
|
end
|
10
10
|
|
11
|
+
class << self
|
12
|
+
def success(message)
|
13
|
+
json = {
|
14
|
+
_meta: {
|
15
|
+
message: "BusinessCase #{business_case.sls_ui} with ScanId #{business_case.scan_id} signedOff"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
new(json, :ok)
|
20
|
+
end
|
21
|
+
|
22
|
+
def error(title: 'Error', message:, status: :internal_server_error, pointer: 'unspecified')
|
23
|
+
json = {
|
24
|
+
errors: [
|
25
|
+
pointer: {
|
26
|
+
source: pointer
|
27
|
+
},
|
28
|
+
title: title,
|
29
|
+
detail: message,
|
30
|
+
]
|
31
|
+
}
|
32
|
+
status = :internal_server_error
|
33
|
+
|
34
|
+
new(json, status)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
11
38
|
def set_data(value)
|
12
39
|
@data = value
|
13
40
|
|
@@ -5,66 +5,56 @@ module Blacksheep
|
|
5
5
|
include ErrorHandler
|
6
6
|
|
7
7
|
def handle(exception)
|
8
|
-
json =
|
8
|
+
json = nil
|
9
|
+
status = :internal_server_error
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# status = :unprocessable_entity # 422
|
23
|
-
# when Pundit::NotAuthorizedError
|
24
|
-
# json = {
|
25
|
-
# errors: [
|
26
|
-
# pointer: {
|
27
|
-
# source: not_authorized_pointer(exception)
|
28
|
-
# },
|
29
|
-
# title: "#{exception.class}",
|
30
|
-
# detail: "#{exception.message}",
|
31
|
-
# ]
|
32
|
-
# }
|
33
|
-
# status = :unauthorized # 401
|
34
|
-
# when Exceptions::AuthenticationInvalid
|
35
|
-
# json = {
|
36
|
-
# errors: [
|
37
|
-
# pointer: {
|
38
|
-
# source: 'Secured Module'
|
39
|
-
# },
|
40
|
-
# title: "#{exception.class}",
|
41
|
-
# detail: "#{exception.message}",
|
42
|
-
# ]
|
43
|
-
# }
|
44
|
-
# status = :unauthorized # 401
|
45
|
-
# else
|
46
|
-
# json = {
|
47
|
-
# errors: [
|
48
|
-
# pointer: {
|
49
|
-
# source: 'Internal'
|
50
|
-
# },
|
51
|
-
# title: "#{exception.class}",
|
52
|
-
# detail: "#{exception.message}",
|
53
|
-
# ]
|
54
|
-
# }
|
55
|
-
# status = :internal_server_error # 500
|
56
|
-
# end
|
11
|
+
case exception
|
12
|
+
when Blacksheep::ActionError
|
13
|
+
json = {
|
14
|
+
errors: [
|
15
|
+
pointer: {
|
16
|
+
source: exception.backtrace.first,
|
17
|
+
identifier: exception.identifier,
|
18
|
+
},
|
19
|
+
title: exception.title,
|
20
|
+
detail: exception.message,
|
21
|
+
]
|
22
|
+
}
|
57
23
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
24
|
+
# when Pundit::NotAuthorizedError
|
25
|
+
# json = {
|
26
|
+
# errors: [
|
27
|
+
# pointer: {
|
28
|
+
# source: not_authorized_pointer(exception)
|
29
|
+
# },
|
30
|
+
# title: "#{exception.class}",
|
31
|
+
# detail: "#{exception.message}",
|
32
|
+
# ]
|
33
|
+
# }
|
34
|
+
# status = :unauthorized # 401
|
35
|
+
# when Exceptions::AuthenticationInvalid
|
36
|
+
# json = {
|
37
|
+
# errors: [
|
38
|
+
# pointer: {
|
39
|
+
# source: 'Secured Module'
|
40
|
+
# },
|
41
|
+
# title: "#{exception.class}",
|
42
|
+
# detail: "#{exception.message}",
|
43
|
+
# ]
|
44
|
+
# }
|
45
|
+
# status = :unauthorized # 401
|
46
|
+
|
47
|
+
else
|
48
|
+
json = {
|
49
|
+
errors: [
|
50
|
+
pointer: {
|
51
|
+
source: 'Internal'
|
52
|
+
},
|
53
|
+
title: "#{exception.class}",
|
54
|
+
detail: "#{exception.message}",
|
55
|
+
]
|
56
|
+
}
|
57
|
+
end
|
68
58
|
|
69
59
|
ActionResult.new(json, status)
|
70
60
|
end
|
data/lib/blacksheep/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacksheep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Schweizer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-matcher
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/blacksheep.rb
|
88
88
|
- lib/blacksheep/action.rb
|
89
89
|
- lib/blacksheep/action_decorator.rb
|
90
|
+
- lib/blacksheep/action_error.rb
|
90
91
|
- lib/blacksheep/action_result.rb
|
91
92
|
- lib/blacksheep/decorators/default_error_handler.rb
|
92
93
|
- lib/blacksheep/decorators/error_handler.rb
|