napa 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/napa/grape_extensions/error_formatter.rb +18 -0
- data/lib/napa/grape_extensions/error_presenter.rb +10 -0
- data/lib/napa/json_error.rb +17 -0
- data/lib/napa/version.rb +1 -1
- data/lib/napa.rb +4 -0
- data/spec/grape_extensions/error_formatter_spec.rb +21 -0
- data/spec/json_error_spec.rb +14 -0
- metadata +68 -29
- checksums.yaml +0 -7
@@ -0,0 +1,18 @@
|
|
1
|
+
if defined?(Grape)
|
2
|
+
module Grape
|
3
|
+
module ErrorFormatter
|
4
|
+
module Json
|
5
|
+
class << self
|
6
|
+
def call(message, backtrace, options = {}, env = nil)
|
7
|
+
result = message.is_a?(Napa::JsonError) ? message : Napa::JsonError.new(:api_error, message)
|
8
|
+
|
9
|
+
if (options[:rescue_options] || {})[:backtrace] && backtrace && !backtrace.empty?
|
10
|
+
result = result.merge(backtrace: backtrace)
|
11
|
+
end
|
12
|
+
MultiJson.dump(result)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/napa/version.rb
CHANGED
data/lib/napa.rb
CHANGED
@@ -4,12 +4,16 @@ require 'dotenv'
|
|
4
4
|
require 'logging'
|
5
5
|
require 'octokit'
|
6
6
|
require 'grape'
|
7
|
+
require 'json'
|
7
8
|
|
8
9
|
# require internal files
|
9
10
|
require 'napa/version'
|
10
11
|
require 'napa/logger/logger'
|
11
12
|
require 'napa/logger/log_transaction'
|
12
13
|
require 'napa/identity'
|
14
|
+
require 'napa/json_error'
|
15
|
+
require 'napa/grape_extensions/error_formatter'
|
16
|
+
require 'napa/grape_extensions/error_presenter'
|
13
17
|
require 'napa/middleware/logger'
|
14
18
|
require 'napa/middleware/app_monitor'
|
15
19
|
require 'napa/activerecord'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'napa/grape_extensions/error_formatter'
|
3
|
+
|
4
|
+
describe Grape::ErrorFormatter::Json do
|
5
|
+
context '#call' do
|
6
|
+
it 'returns an api_error for plain error messages' do
|
7
|
+
error = Grape::ErrorFormatter::Json.call('test message', nil)
|
8
|
+
parsed = JSON.parse(error)
|
9
|
+
parsed['error']['code'].should eq('api_error')
|
10
|
+
parsed['error']['message'].should eq('test message')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a specified error when given a Napa::JsonError object' do
|
14
|
+
json_error = Napa::JsonError.new(:foo, 'bar')
|
15
|
+
error = Grape::ErrorFormatter::Json.call(json_error, nil)
|
16
|
+
parsed = JSON.parse(error)
|
17
|
+
parsed['error']['code'].should eq('foo')
|
18
|
+
parsed['error']['message'].should eq('bar')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'napa/json_error'
|
3
|
+
|
4
|
+
describe Napa::JsonError do
|
5
|
+
context '#to_json' do
|
6
|
+
it 'returns a json hash with the error data' do
|
7
|
+
error = Napa::JsonError.new(:code, 'message').to_json
|
8
|
+
parsed = JSON.parse(error)
|
9
|
+
|
10
|
+
parsed['error']['code'].should eq('code')
|
11
|
+
parsed['error']['message'].should eq('message')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,68 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: napa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Darby Frey
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- - '>='
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- - '>='
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: logging
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: dotenv
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- - '>='
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- - '>='
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: octokit
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :runtime
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -69,113 +78,129 @@ dependencies:
|
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: virtus
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
|
-
- - '>='
|
83
|
+
- - ! '>='
|
74
84
|
- !ruby/object:Gem::Version
|
75
85
|
version: '0'
|
76
86
|
type: :runtime
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
|
-
- - '>='
|
91
|
+
- - ! '>='
|
81
92
|
- !ruby/object:Gem::Version
|
82
93
|
version: '0'
|
83
94
|
- !ruby/object:Gem::Dependency
|
84
95
|
name: grape
|
85
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
86
98
|
requirements:
|
87
|
-
- - '>='
|
99
|
+
- - ! '>='
|
88
100
|
- !ruby/object:Gem::Version
|
89
101
|
version: '0'
|
90
102
|
type: :runtime
|
91
103
|
prerelease: false
|
92
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
93
106
|
requirements:
|
94
|
-
- - '>='
|
107
|
+
- - ! '>='
|
95
108
|
- !ruby/object:Gem::Version
|
96
109
|
version: '0'
|
97
110
|
- !ruby/object:Gem::Dependency
|
98
111
|
name: grape-swagger
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
100
114
|
requirements:
|
101
|
-
- - '>='
|
115
|
+
- - ! '>='
|
102
116
|
- !ruby/object:Gem::Version
|
103
117
|
version: '0'
|
104
118
|
type: :runtime
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
107
122
|
requirements:
|
108
|
-
- - '>='
|
123
|
+
- - ! '>='
|
109
124
|
- !ruby/object:Gem::Version
|
110
125
|
version: '0'
|
111
126
|
- !ruby/object:Gem::Dependency
|
112
127
|
name: unicorn
|
113
128
|
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
114
130
|
requirements:
|
115
|
-
- - '>='
|
131
|
+
- - ! '>='
|
116
132
|
- !ruby/object:Gem::Version
|
117
133
|
version: '0'
|
118
134
|
type: :runtime
|
119
135
|
prerelease: false
|
120
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
121
138
|
requirements:
|
122
|
-
- - '>='
|
139
|
+
- - ! '>='
|
123
140
|
- !ruby/object:Gem::Version
|
124
141
|
version: '0'
|
125
142
|
- !ruby/object:Gem::Dependency
|
126
143
|
name: rspec
|
127
144
|
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
128
146
|
requirements:
|
129
|
-
- - '>='
|
147
|
+
- - ! '>='
|
130
148
|
- !ruby/object:Gem::Version
|
131
149
|
version: '0'
|
132
150
|
type: :development
|
133
151
|
prerelease: false
|
134
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
135
154
|
requirements:
|
136
|
-
- - '>='
|
155
|
+
- - ! '>='
|
137
156
|
- !ruby/object:Gem::Version
|
138
157
|
version: '0'
|
139
158
|
- !ruby/object:Gem::Dependency
|
140
159
|
name: pry
|
141
160
|
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
142
162
|
requirements:
|
143
|
-
- - '>='
|
163
|
+
- - ! '>='
|
144
164
|
- !ruby/object:Gem::Version
|
145
165
|
version: '0'
|
146
166
|
type: :development
|
147
167
|
prerelease: false
|
148
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
149
170
|
requirements:
|
150
|
-
- - '>='
|
171
|
+
- - ! '>='
|
151
172
|
- !ruby/object:Gem::Version
|
152
173
|
version: '0'
|
153
174
|
- !ruby/object:Gem::Dependency
|
154
175
|
name: git
|
155
176
|
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
156
178
|
requirements:
|
157
|
-
- - '>='
|
179
|
+
- - ! '>='
|
158
180
|
- !ruby/object:Gem::Version
|
159
181
|
version: '0'
|
160
182
|
type: :development
|
161
183
|
prerelease: false
|
162
184
|
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
163
186
|
requirements:
|
164
|
-
- - '>='
|
187
|
+
- - ! '>='
|
165
188
|
- !ruby/object:Gem::Version
|
166
189
|
version: '0'
|
167
190
|
- !ruby/object:Gem::Dependency
|
168
191
|
name: rubocop
|
169
192
|
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
170
194
|
requirements:
|
171
|
-
- - '>='
|
195
|
+
- - ! '>='
|
172
196
|
- !ruby/object:Gem::Version
|
173
197
|
version: '0'
|
174
198
|
type: :development
|
175
199
|
prerelease: false
|
176
200
|
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
177
202
|
requirements:
|
178
|
-
- - '>='
|
203
|
+
- - ! '>='
|
179
204
|
- !ruby/object:Gem::Version
|
180
205
|
version: '0'
|
181
206
|
description: A simple framework for building APIs with Grape
|
@@ -215,7 +240,10 @@ files:
|
|
215
240
|
- lib/napa.rb
|
216
241
|
- lib/napa/activerecord.rb
|
217
242
|
- lib/napa/grape_api.rb
|
243
|
+
- lib/napa/grape_extensions/error_formatter.rb
|
244
|
+
- lib/napa/grape_extensions/error_presenter.rb
|
218
245
|
- lib/napa/identity.rb
|
246
|
+
- lib/napa/json_error.rb
|
219
247
|
- lib/napa/logger/log_transaction.rb
|
220
248
|
- lib/napa/logger/logger.rb
|
221
249
|
- lib/napa/middleware/app_monitor.rb
|
@@ -226,36 +254,47 @@ files:
|
|
226
254
|
- lib/tasks/git.rake
|
227
255
|
- lib/tasks/routes.rake
|
228
256
|
- napa.gemspec
|
257
|
+
- spec/grape_extensions/error_formatter_spec.rb
|
229
258
|
- spec/identity_spec.rb
|
259
|
+
- spec/json_error_spec.rb
|
230
260
|
- spec/logger/log_transaction_spec.rb
|
231
261
|
- spec/spec_helper.rb
|
232
262
|
- spec/version_spec.rb
|
233
263
|
- tasks/version.rake
|
234
264
|
homepage: ''
|
235
265
|
licenses: []
|
236
|
-
metadata: {}
|
237
266
|
post_install_message:
|
238
267
|
rdoc_options: []
|
239
268
|
require_paths:
|
240
269
|
- lib
|
241
270
|
required_ruby_version: !ruby/object:Gem::Requirement
|
271
|
+
none: false
|
242
272
|
requirements:
|
243
|
-
- - '>='
|
273
|
+
- - ! '>='
|
244
274
|
- !ruby/object:Gem::Version
|
245
275
|
version: '0'
|
276
|
+
segments:
|
277
|
+
- 0
|
278
|
+
hash: 1127754833673535971
|
246
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
|
+
none: false
|
247
281
|
requirements:
|
248
|
-
- - '>='
|
282
|
+
- - ! '>='
|
249
283
|
- !ruby/object:Gem::Version
|
250
284
|
version: '0'
|
285
|
+
segments:
|
286
|
+
- 0
|
287
|
+
hash: 1127754833673535971
|
251
288
|
requirements: []
|
252
289
|
rubyforge_project:
|
253
|
-
rubygems_version:
|
290
|
+
rubygems_version: 1.8.25
|
254
291
|
signing_key:
|
255
|
-
specification_version:
|
292
|
+
specification_version: 3
|
256
293
|
summary: A simple framework for building APIs with Grape
|
257
294
|
test_files:
|
295
|
+
- spec/grape_extensions/error_formatter_spec.rb
|
258
296
|
- spec/identity_spec.rb
|
297
|
+
- spec/json_error_spec.rb
|
259
298
|
- spec/logger/log_transaction_spec.rb
|
260
299
|
- spec/spec_helper.rb
|
261
300
|
- spec/version_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 4fe0fa94a5dd767848ebc3aa7cd844852d337fe0
|
4
|
-
data.tar.gz: c3a75f4bc02be82326a6b4c84a5b7a822e5053dd
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 120c728a6838492420a2c97b5e4aa35e0c6ce1cf1be1223076d60f0a6304211a67d919c0433a3abce911d2e1991ff3694c3a17682239832bf673797cb83d8107
|
7
|
-
data.tar.gz: 8c745d7661deba0db7ccdb4bb163f880cae94306f4d01949a7a15d11cd4bb42396792f09e1694d4252aae98fe0f2b195d7923a473c05d5265113f83bd12d30be
|