Skip to content
Pedro Belo edited this page Jul 23, 2015 · 1 revision

Pliny comes with a middleware to handle application errors. It serializes, logs and tracks exceptions raised in your app.

Logging

The middleware will log any exceptions raised in your app using the Log format:

request_id=a11d018e-ad2b-4abd-afea-9a080f103183 instrumentation at=start method=GET 
request_id=a11d018e-ad2b-4abd-afea-9a080f103183 instrumentation at=finish method=GET path=/ route_signature=/ status=500 elapsed=0.088

It also logs the exception class name, message and backtrace to the server logs so you can easily see what happened:

SocketError - SocketError:
 /dev/pliny-app/lib/endpoints/root.rb:4:in `block in <class:Root>'
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `call'
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `block 
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `[]'
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block 
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:993:in 
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block 
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:1014:in `block 
 /dev/ruby-2.2.2/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in `catch'

Serialization

All exceptions are serialized as JSON to users, using the following pattern:

{"id":"unauthorized","message":"Missing API credentials"}

As you can see Pliny identifies exceptions with a unique id, which is helpful when the HTTP status code alone is not enough to help clients recover from errors.