Skip to content
This repository
Browse code

better error message handling

  • Loading branch information...
commit a4409e6beed43dd7ae89a886940a530755467e81 1 parent b1371f4
Mislav Marohnić authored

Showing 1 changed file with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. +11 3 app.rb
14 app.rb
@@ -172,9 +172,15 @@ def log_instagram_error(boom = $!)
172 172 end
173 173
174 174 error do
175   - log_error env['sinatra.error']
  175 + err = env['sinatra.error']
  176 + log_error err
176 177 status 500
177   - haml "%h1 Error: can't perform this operation\n%p Please, try again later."
  178 +
  179 + if err.respond_to?(:response) and err.response[:body] and msg = err.response[:body]['error_message']
  180 + haml "%h1 Error from Instagram\n%p #{msg}"
  181 + else
  182 + haml "%h1 Error: can't perform this operation\n%p Please, try again later."
  183 + end
178 184 end
179 185
180 186 get '/' do
@@ -256,7 +262,9 @@ def log_instagram_error(boom = $!)
256 262 @per_page = 20
257 263 rescue Faraday::Error::ClientError => e
258 264 log_instagram_error
259   - message = e.response[:body]['meta']['error_message']
  265 + message = if body = e.response[:body]
  266 + body['meta'] && body['meta']['error_message'] || body['error_message']
  267 + end
260 268
261 269 if "this user does not exist" == message
262 270 User.delete params[:id]

0 comments on commit a4409e6

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