Skip to content
Browse files

better error message handling

  • Loading branch information...
1 parent b1371f4 commit a4409e6beed43dd7ae89a886940a530755467e81 @mislav committed Feb 6, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 app.rb
View
14 app.rb
@@ -172,9 +172,15 @@ def log_instagram_error(boom = $!)
end
error do
- log_error env['sinatra.error']
+ err = env['sinatra.error']
+ log_error err
status 500
- haml "%h1 Error: can't perform this operation\n%p Please, try again later."
+
+ if err.respond_to?(:response) and err.response[:body] and msg = err.response[:body]['error_message']
+ haml "%h1 Error from Instagram\n%p #{msg}"
+ else
+ haml "%h1 Error: can't perform this operation\n%p Please, try again later."
+ end
end
get '/' do
@@ -256,7 +262,9 @@ def log_instagram_error(boom = $!)
@per_page = 20
rescue Faraday::Error::ClientError => e
log_instagram_error
- message = e.response[:body]['meta']['error_message']
+ message = if body = e.response[:body]
+ body['meta'] && body['meta']['error_message'] || body['error_message']
+ end
if "this user does not exist" == message
User.delete params[:id]

0 comments on commit a4409e6

Please sign in to comment.
Something went wrong with that request. Please try again.