jimson 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.9.0 / 2012-08-22
2
+
3
+ * Minor enhancements
4
+
5
+ * Add show_errors option to server, which will cause application errors to include the error name and the first line of the backtrace
6
+
1
7
  == 0.8.0 / 2012-08-17
2
8
 
3
9
  * Major enhancements
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.9.0
data/lib/jimson/server.rb CHANGED
@@ -61,6 +61,7 @@ module Jimson
61
61
 
62
62
  @host = opts.delete(:host) || '0.0.0.0'
63
63
  @port = opts.delete(:port) || 8999
64
+ @show_errors = opts.delete(:show_errors) || false
64
65
  @opts = opts
65
66
  end
66
67
 
@@ -168,7 +169,7 @@ module Jimson
168
169
  rescue ArgumentError
169
170
  raise Server::Error::InvalidParams.new
170
171
  rescue Exception, StandardError => e
171
- raise Server::Error::ApplicationError.new(e)
172
+ raise Server::Error::ApplicationError.new(e, @show_errors)
172
173
  end
173
174
 
174
175
  def dispatch_request(method, params)
@@ -47,8 +47,10 @@ module Jimson
47
47
  end
48
48
 
49
49
  class ApplicationError < Error
50
- def initialize(err)
51
- super(-32099, "Server application error")
50
+ def initialize(err, show_error = false)
51
+ msg = "Server application error"
52
+ msg += ': ' + err.message + ' at ' + err.backtrace.first if show_error
53
+ super(-32099, msg)
52
54
  end
53
55
  end
54
56
 
data/spec/server_spec.rb CHANGED
@@ -239,23 +239,51 @@ module Jimson
239
239
  end
240
240
 
241
241
  describe "receiving a call for ugly method" do
242
- it "returns only global error without stack trace" do
243
- req = {
244
- 'jsonrpc' => '2.0',
245
- 'method' => 'ugly_method',
246
- 'id' => 1
247
- }
248
- post_json(req)
242
+ context "by default" do
243
+ it "returns only global error without stack trace" do
244
+ req = {
245
+ 'jsonrpc' => '2.0',
246
+ 'method' => 'ugly_method',
247
+ 'id' => 1
248
+ }
249
+ post_json(req)
249
250
 
250
- resp = MultiJson.decode(last_response.body)
251
- resp.should == {
252
- 'jsonrpc' => '2.0',
253
- 'error' => {
254
- 'code' => -32099,
255
- 'message' => 'Server application error'
256
- },
257
- 'id' => 1
258
- }
251
+ resp = MultiJson.decode(last_response.body)
252
+ resp.should == {
253
+ 'jsonrpc' => '2.0',
254
+ 'error' => {
255
+ 'code' => -32099,
256
+ 'message' => 'Server application error'
257
+ },
258
+ 'id' => 1
259
+ }
260
+ end
261
+ end
262
+
263
+ context "with 'show_errors' enabled" do
264
+ it "returns an error name and first line of the stack trace" do
265
+ req = {
266
+ 'jsonrpc' => '2.0',
267
+ 'method' => 'ugly_method',
268
+ 'id' => 1
269
+ }
270
+
271
+ app = Server.new(router, :environment => "production", :show_errors => true)
272
+
273
+ # have to make a new Rack::Test browser since this server is different than the normal one
274
+ browser = Rack::Test::Session.new(Rack::MockSession.new(app))
275
+ browser.post '/', MultiJson.encode(req), {'Content-Type' => 'application/json'}
276
+
277
+ resp = MultiJson.decode(browser.last_response.body)
278
+ resp.should == {
279
+ 'jsonrpc' => '2.0',
280
+ 'error' => {
281
+ 'code' => -32099,
282
+ 'message' => "Server application error: RuntimeError at /home/chris/repos/jimson/spec/server_spec.rb:40:in `ugly_method'"
283
+ },
284
+ 'id' => 1
285
+ }
286
+ end
259
287
  end
260
288
  end
261
289
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-17 00:00:00.000000000 Z
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blankslate