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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b520c717b2b72704b7f6854ce506fca8e47773a3b2fe48d54344d2622a9ac8b
4
- data.tar.gz: b3dfe30943535dbc03e6a9e81c088e2267528c775aa484524d12710e50b2cf64
3
+ metadata.gz: 75c49ec47c41acddb7ed3dc1ce015c75d427dfc26107c2bd8687243c7d05d0a6
4
+ data.tar.gz: 7f45f1fecf5e97585778edc375c225ccff65c668a6f23a8c6b539b4c52b475dd
5
5
  SHA512:
6
- metadata.gz: 3d3ee10c9acc1381e10e95101c42d7bbd17b6972c94b526aabc28b1b142bec56634da37b2ff0bd71f752ec158846ba888439af2d87bd3120c4fdda7e0a75c010
7
- data.tar.gz: '0401960e858de894e369599234431f8c91014e5ea0419924d00bb20396c48dd50d3faa04f2fa0d266f79e3d10795e9ad93ffa1ae45aa72b232d786a0a44db8e4'
6
+ metadata.gz: 00f30d27444904c1f63c696a8492f5173832cb47797dacfdd8261d77bdfed70ba6b63bb2c58abd08f17ddde071d547598ae354e29f95487dedd64af2874c56eb
7
+ data.tar.gz: 8e154027acc2c66f1cf5b22968174157eacb11a5fcc06de33eaf4f0bbeed754219646cec79199f919e304c1a312fcd2b3318f3d0961cbb20eda57c28bbf7ba5c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blacksheep (0.2.3)
4
+ blacksheep (0.3.0)
5
5
  dry-matcher
6
6
 
7
7
  GEM
data/lib/blacksheep.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "blacksheep/version"
2
2
  require "blacksheep/action_result"
3
+ require "blacksheep/action_error"
3
4
  require "blacksheep/action_decorator"
4
5
  require "blacksheep/decorators/error_handler"
5
6
  require "blacksheep/decorators/default_error_handler"
@@ -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 = status = nil
8
+ json = nil
9
+ status = :internal_server_error
9
10
 
10
- # case exception
11
- # when Exceptions::ValidationException
12
- # errors = []
13
- # exception.model.errors.each do |attribute, message|
14
- # errors << {
15
- # title: "'#{attribute}' validation error",
16
- # detail: message,
17
- # }
18
- # end
19
- # json = {
20
- # errors: errors
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
- json = {
59
- errors: [
60
- pointer: {
61
- source: 'Internal'
62
- },
63
- title: "#{exception.class}",
64
- detail: "#{exception.message}",
65
- ]
66
- }
67
- status = :internal_server_error # 500
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
@@ -1,3 +1,3 @@
1
1
  module Blacksheep
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.3
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-18 00:00:00.000000000 Z
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