-
Notifications
You must be signed in to change notification settings - Fork 183
Errors
Steven Davidovitz edited this page Jun 10, 2013
·
3 revisions
Resources continue to work the same, however additional methods have been added.
For all #find, #create, #save, #update, #destroy methods, a similarly-named method with a bang (e.g. #save -> #save!) has been added that will not rescue errors and will instead pass them to the user.
For example:
ticket = ZendeskAPI::Ticket.new(client, :subject => "test")
ticket.save # => false; Will store errors on ticket.errors
ticket.save! # => raises ZendeskAPI::Error::RecordInvalid
The default behavior for collections also hasn't changed but, similar to resources, helper methods have been added that will not rescue errors.
For instance, ZendeskAPI::Collection#fetch! has been added. However, array methods called on an unloaded collection will not raise an error.
tickets = client.tickets(:path => "/nonexistent") # => ZendeskAPI::Collection
tickets.fetch # => []
tickets.fetch! # => raises ZendeskAPI::Error::RecordNotFound
# The following will output nothing and raise no errors:
tickets.map {|ticket| puts ticket}
The following methods have been added to ZendeskAPI::Collection: #fetch!, #count!, #save!, #to_a!, #all!.