-
Notifications
You must be signed in to change notification settings - Fork 22
Webhook Migration 1.2.x to 1.3.0
As the Changes.md and Readme.md detail, we have changed the error handling system and payload processing in the Parse::Webhooks
class. Here is a short migration guide to what has changed and how you should update your code for the new version.
- Change all exception
raise "...msg..."
witherror!("...msg...")
. - Remove the use of
payload
as an incoming argument and use methods directly. - Verify if you need to additional handle exceptions.
Before you would return an error to Parse from a cloud hook or function by raising an exception. In order to support the cases where you want to catch internal system errors in the stack by other components, we now require that you explicitly call error!()
method to return a Parse error to the client.
If you code looked like this before:
class Artist < Parse::Object
# before_save trigger example
webhook :before_save do
raise "My error message" if user.nil?
# ... do stuff ...
end
end
# cloud function example
Parse::Webhooks.route :function, "helloWorld" do
raise "No parameters!" if params.empty?
# ... do stuff ...
end
it should now be:
class Artist < Parse::Object
# before_save trigger example
webhook :before_save do
error!("My error message") if user.nil?
# ... do stuff ...
end
end
# cloud function example
Parse::Webhooks.route :function, "helloWorld" do
error!("No parameters!") if params.empty?
# ... do stuff ...
end
The block in which Cloud Code functions and triggers/hooks occur are now binded to the Parse::Payload
object. If your code looked like this before:
class Artist < Parse::Object
# before_save trigger example
webhook :before_save do |payload|
artist = payload.parse_object
the_user = payload.user
# .. do stuff ...
artist.update_payload
end
end
# cloud function example
Parse::Webhooks.route :function, "helloWorld" do |payload|
my_param = payload.params["my_param"]
the_user = payload.user
# ... do stuff ...
end
you can now discard the payload
parameter and access methods directly:
class Artist < Parse::Object
# before_save trigger example
webhook :before_save do
artist = parse_object
the_user = user
# .. do stuff ...
true
end
end
# cloud function example
Parse::Webhooks.route :function, "helloWorld" do
my_param = params["my_param"]
the_user = user
# ... do stuff ...
end
For specific Parse and HTTP status error codes, we will raise an exception. This in conjunction with the new save!
method, will better debugging of your applications (ex. using Sentry) and allow systems like Sidekiq
to retry any workers when specific exceptions are raised in whose task can be retried at a later time. The list of new exceptions is as follows:
-
Parse::RequestLimitExceededError
- occurs when you have exceeded your request limit on Parse. This is usually Parse error155
. -
Parse::AuthenticationError
- occurs when you have invalid credentials. This is usually returned by Parse as HTTP status code of401
and403
. -
Parse::TimeoutError
- occurs on a net/http timeout request. This is usually error code124
(Parse) or143
(net/http layer). -
Parse::ProtocolError
- occurs when there is an issue with the request. This is usually HTTP status code405
and406
. -
Parse::ConnectionError
- occurs when the API request could not be fulfilled (API issue or failed network connection). -
Parse::ServerError
- occurs in all other cases when there is a critical error. This is usually any time Parse server returns an error code of<=100
or a HTTP status code of500
.