Global Exceptions for Salvation and Registration at Sinatra

How to specify global salvation in the event of an exception, and if you use Sinatra for an API or application, how do you handle logging?

+5
source share
2 answers

404s can be processed using a method not_found, for example, for example:

not_found do
  'Site does not exist.'
end

500s can be processed by calling the error method using a block, for example:

error do
  "Application error. Pls try later."
end

Details of the error can be obtained through sinatra.errorin request.env, for example:

error do
  'An error occured: ' + request.env['sinatra.error'].message
end
+6
source

dev - , show_exceptions false synatra.

class BaseApp < Sinatra::Base

  configure { set :show_exceptions, false }

  error do |err|
    raise "Error: #{err}"
  end

end

, true, , , , , .

+4

All Articles