Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Mo better errors #92

Open
wants to merge 1 commit into from

3 participants

@goofrider

Expand on Pull #89 "Provide more descriptive exception messages" (djanowski).

#89

Move @code and @desription in a separate set_response_code method so it can be overriden by subclass. As other OAuth2 providers may use non-standard key names for errors.

An example for a subclass of OAuth2::Error that needs to change the error @code/@description setters.

Old:
https://github.com/acenqiu/weibo2/blob/master/lib/weibo2/error.rb

New:
https://github.com/goofrider/weibo2/blob/master/lib/weibo2/error.rb

@tomrossi7

+1 from me!!

@guilhermesimoes

This really should have been merged a long time ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2012
  1. Adding Error class setter method for more reliable errors messages fo…

    Jeffrey Chan authored
    …r subclass
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 3 deletions.
  1. +14 −3 lib/oauth2/error.rb
View
17 lib/oauth2/error.rb
@@ -10,9 +10,9 @@ def initialize(response)
message = []
- if response.parsed.is_a?(Hash)
- @code = response.parsed['error']
- @description = response.parsed['error_description']
+ set_response_code(response)
+
+ if @code
message << "#{@code}: #{@description}"
end
@@ -20,5 +20,16 @@ def initialize(response)
super(message.join("\n"))
end
+
+ ## Subclass should override this if repsonse use different keys for error code/description
+ ## E.g. https://github.com/acenqiu/weibo2/blob/master/lib/weibo2/error.rb
+ def set_response_code(response)
+ if response.parsed.is_a?(Hash)
+ @code = response.parsed['error']
+ @description = response.parsed['error_description']
+ end
+ end
+
+
end
end
Something went wrong with that request. Please try again.