arkaan 0.9.4 → 0.9.5

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
  SHA1:
3
- metadata.gz: eb89a3cc4c7c8adebbf42326603d7fe99bf184da
4
- data.tar.gz: afc1b8920982ca318578dcede3d994fffb250a66
3
+ metadata.gz: 2a311220ec19ed965a2f2074c3dfb5e499c36726
4
+ data.tar.gz: 4a6c21a2a90b14fa500384177d4b6cb4a8bf4bf6
5
5
  SHA512:
6
- metadata.gz: c4db231c2094372bc78ffc0485d0b19e08b251c46df5b36fc3b742c84a69b2b8b8f3df76b226b5e27ec306815e5b6b7518d9bb060acdea00cb9fa6074c5846a1
7
- data.tar.gz: 20253c02ecb2fa8e2a0f90bb8324763007475d2ec49aff16c814a66943b9efbb37d3294f25f057f9c5c7616cdea3d184929624c9c71ff112f6470c3821a5d494
6
+ metadata.gz: ebe0ae16361d0d2dde20e431d5d3a9c8ff6418ec9ad8de4347919a54109cec6bea8162f1f29517f7acaff89b0d3ae41a9b5880a40f0a70661ec8d1107eb83f89
7
+ data.tar.gz: ab0ba25a2a172c283a2a3fd6a56ad776c84527a6c614dd7ebbea3c262fa3c95aa3dd867bafb80aa92178c003b5b3984885578e7190974f4471f0f7ea1e42ae26
@@ -3,6 +3,7 @@ module Arkaan
3
3
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
4
  module Utils
5
5
  autoload :Controller , 'arkaan/utils/controller'
6
+ autoload :Errors , 'arkaan/utils/errors'
6
7
  autoload :MicroService, 'arkaan/utils/micro_service'
7
8
  end
8
9
  end
@@ -120,6 +120,22 @@ module Arkaan
120
120
  def select_params(*fields)
121
121
  return params.select { |key, value| fields.include?(key) }
122
122
  end
123
+
124
+ def handle_arkaan_exception(exception)
125
+ custom_error(exception.status, "#{exception.action}.#{exception.field}.#{exception.error}")
126
+ end
127
+
128
+ error Arkaan::Utils::Errors::BadRequest do |exception|
129
+ handle_arkaan_exception(exception)
130
+ end
131
+
132
+ error Arkaan::Utils::Errors::Forbidden do |exception|
133
+ handle_arkaan_exception(exception)
134
+ end
135
+
136
+ error Arkaan::Utils::Errors::NotFound do |exception|
137
+ handle_arkaan_exception(exception)
138
+ end
123
139
  end
124
140
  end
125
141
  end
@@ -0,0 +1,9 @@
1
+ module Arkaan
2
+ module Utils
3
+ module Errors
4
+ autoload :BadRequest, 'arkaan/utils/errors/bad_request'
5
+ autoload :Forbidden , 'arkaan/utils/errors/forbidden'
6
+ autoload :NotFound , 'arkaan/utils/errors/not_found'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Arkaan
2
+ module Utils
3
+ module Errors
4
+ class BadRequest < StandardError
5
+ attr_accessor :field
6
+
7
+ attr_accessor :action
8
+
9
+ attr_accessor :error
10
+
11
+ def initialize(action:, field:, error:)
12
+ @action = action
13
+ @field = field
14
+ @error = error
15
+ end
16
+
17
+ def status
18
+ return 400
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Arkaan
2
+ module Utils
3
+ module Errors
4
+ class Forbidden < StandardError
5
+ attr_accessor :field
6
+
7
+ attr_accessor :action
8
+
9
+ attr_accessor :error
10
+
11
+ def initialize(action:, field:, error:)
12
+ @action = action
13
+ @field = field
14
+ @error = error
15
+ end
16
+
17
+ def status
18
+ return 403
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Arkaan
2
+ module Utils
3
+ module Errors
4
+ class NotFound < StandardError
5
+ attr_accessor :field
6
+
7
+ attr_accessor :action
8
+
9
+ attr_accessor :error
10
+
11
+ def initialize(action:, field:, error:)
12
+ @action = action
13
+ @field = field
14
+ @error = error
15
+ end
16
+
17
+ def status
18
+ return 404
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-18 00:00:00.000000000 Z
11
+ date: 2018-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-json_expectations
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rack-test
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -230,6 +244,10 @@ files:
230
244
  - lib/arkaan/specs.rb
231
245
  - lib/arkaan/utils.rb
232
246
  - lib/arkaan/utils/controller.rb
247
+ - lib/arkaan/utils/errors.rb
248
+ - lib/arkaan/utils/errors/bad_request.rb
249
+ - lib/arkaan/utils/errors/forbidden.rb
250
+ - lib/arkaan/utils/errors/not_found.rb
233
251
  - lib/arkaan/utils/micro_service.rb
234
252
  - lib/arkaan/utils/seeder.rb
235
253
  homepage: https://rubygems.org/gems/arkaan