lib/withings/error.rb in simplificator-withings-0.2.2 vs lib/withings/error.rb in simplificator-withings-0.2.3
- old
+ new
@@ -1,22 +1,32 @@
class Withings::ApiError < StandardError
+ UNKNOWN_STATUS_CODE = lambda() {|status, path, params| "Unknown status code '#{status}'"}
STATUS_CODES = {
- 100 => "The hash is missing, invalid, or does not match the provided email",
- 247 => "The userid is either absent or incorrect",
- 250 => "The userid and publickey provided do not match, or the user does not share its data",
- 264 => "The email address provided is either unknown or invalid",
- 293 => "The callback URL is either absent or incorrect",
- 294 => "No such subscription could be deleted",
- 304 => "The comment is either absent or incorrect",
- 2555 => "An unknown error occurred",
+ 100 => lambda() {|status, path, params| "The hash '#{params[:hash]}' does not match the email '#{params[:email]}'"},
+ 247 => lambda() {|status, path, params| "The '#{params[:userid]}' is invalid"},
+ 250 => lambda() {|status, path, params| "The userid '#{params[:userid]}' and publickey '#{params[:publickey]}' do not match, or the user does not share its data"},
+ 264 => lambda() {|status, path, params| "The email address '#{params[:email]}' is either unknown or invalid"},
+ 286 => lambda() {|status, path, params| "No subscription for '#{params[:callbackurl]}' was found" },
+ 293 => lambda() {|status, path, params| "The callback URL '#{params[:callbackurl]}' is either unknown or invalid"},
+ 294 => lambda() {|status, path, params| "Could not delete subscription for '#{params[:callbackurl]}'"},
+ 304 => lambda() {|status, path, params| "The comment '#{params[:comment]}' is invalid"},
+ 2554 => lambda() {|status, path, params| "Unknown action '#{params[:action]}' for '#{path}'"},
+ 2555 => lambda() {|status, path, params| "An unknown error occurred"},
}
attr_reader :status
- def initialize(status)
- super(STATUS_CODES[status] || "Undefined status code. We do not have any description about the code #{status}. If you know more, then please let me know.")
+ def initialize(status, path, params)
+ super(build_message(status, path, params))
@status = status
end
def to_s
super + " - Status code: #{self.status}"
+ end
+
+
+ protected
+
+ def build_message(status, path, params)
+ (STATUS_CODES[status] || UNKNOWN_STATUS_CODE).call(status, path, params)
end
end
\ No newline at end of file