Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ability to override error messages

  • Loading branch information...
commit a6b767a1e91d85995dc6ef0c730a4fa4dfeb2622 1 parent a6588f3
@nbibler authored
View
32 lib/devpay/helpers/graceful_requestor.rb
@@ -52,10 +52,40 @@ def self.activate!(activation_key, product_token, access_key_id = Devpay.access_
Devpay::Errors::LicenseService::UserNotSubscribed
ActivationResponse.new({
:code => $!.class.to_s,
- :message => $!.message
+ :message => custom_message_for($!) || $!.message
})
end
+
+ private
+
+
+ ##
+ # Inherit this class into a custom requestor class and override this
+ # method to return custom error messages for error codes.
+ #
+ # ===== Example
+ #
+ # Below is an example of how to add custom error messages to your
+ # application through the response messages:
+ #
+ # def self.custom_devpay_message_for(error)
+ # case error
+ # when Devpay::Errors::LicenseService::ExpiredActivationKey
+ # %w(
+ # The activation key you've provided has expired. Please go
+ # to your Amazon activation page and generate a new activation
+ # key.
+ # )
+ # else
+ # nil # Uses the Amazon error message.
+ # end
+ # end
+ #
+ def self.custom_message_for(error)
+ nil
+ end
+
end
end
View
13 test/graceful_requestor_test.rb
@@ -57,7 +57,18 @@ class GracefulRequestorTest < Test::Unit::TestCase
end
-
+ context "with custom messages" do
+
+ setup do
+ @requestor.stubs(:custom_message_for).returns("Custom error message")
+ end
+
+ should "return the custom message" do
+ assert_equal "Custom error message", @requestor.activate!(TEST_ACTIVATION_KEY, TEST_PRODUCT_TOKEN).message
+ end
+
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.