As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
I am using saveObject method on the client side (iOS) and in the doPreSave method set
response.body ={message:"Some text "};
response.complete(201);
upon certain condition so the object is not saved and the message sent back to the user. However, I can't find a way to get that response.body value in the client. objectsOrNil contains the same object to be saved that was sent via request and not the message I need to pass to the user.
Best Answer
P
Pranav J
said
over 6 years ago
Hey Mark,
In your collection->PreSave hook(), you can handle the condition as an error condition as below:
if (!result._id) {
response.error("No Rooms Available");
}
In your iOS code, you can retrieve the error message using localizedFailureReason:
store.saveObject(
jobRole1,
withCompletionBlock: { (objectsOrNil: [AnyObject]!, errorOrNil: NSError!) -> Void in
if errorOrNil != nil {
//save failed
NSLog("Save failed with error: %@", errorOrNil.localizedFailureReason!)
} else {
//save was successful
NSLog("Successfully saved”)
}
},
withProgressBlock: nil
)
Ideally, you should use in response.continue in case of success for presave hooks and response.error to report an error.
The returned object contains the complete objecct saved in the backend.
Regards,
Wani
Kinvey Support
M
Mark L
said
over 6 years ago
Hello Wani,
Thank you for the prompt reply. I have read and used the guides since working with Kinvey SDK. It is this tutorial example has inspired me for this approach.
response.complete();// completes the request and returns the result to the client
}
The question is how do you extract this message on the client side if the object is not saved as is the case in this example. I totally understand the usual case when the object is saved.
Thank you,
Mark
P
Pranav J
said
over 6 years ago
Answer
Hey Mark,
In your collection->PreSave hook(), you can handle the condition as an error condition as below:
if (!result._id) {
response.error("No Rooms Available");
}
In your iOS code, you can retrieve the error message using localizedFailureReason:
store.saveObject(
jobRole1,
withCompletionBlock: { (objectsOrNil: [AnyObject]!, errorOrNil: NSError!) -> Void in
if errorOrNil != nil {
//save failed
NSLog("Save failed with error: %@", errorOrNil.localizedFailureReason!)
} else {
//save was successful
NSLog("Successfully saved”)
}
},
withProgressBlock: nil
)
Let me know if it works for you.
Thanks, Pranav Kinvey Support
M
Mark L
said
over 6 years ago
Hi Pranav,
I think it is a good enough solution and should work for us although we may or may not have to check for a real error in the message, not sure at this point.
Mark L
I am using saveObject method on the client side (iOS) and in the doPreSave method set
response.body = {message: "Some text "};
response.complete(201);
upon certain condition so the object is not saved and the message sent back to the user. However, I can't find a way to get that response.body value in the client. objectsOrNil contains the same object to be saved that was sent via request and not the message I need to pass to the user.
In your collection->PreSave hook(), you can handle the condition as an error condition as below:
In your iOS code, you can retrieve the error message using localizedFailureReason:
Let me know if it works for you.
Thanks,
Pranav
Kinvey Support
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstWani
Hi,
As you can see in the documentation http://devcenter.kinvey.com/ios/guides/datastore#Saving for saveObject method of iOS SDK, the method always returns an array of objects on success.
I would suggest you go through Business Logic Guide: http://devcenter.kinvey.com/ios/guides/business-logic to understand the use of collection hooks better.
Regards,
Wani
Kinvey Support
Mark L
Hello Wani,
Thank you for the prompt reply. I have read and used the guides since working with Kinvey SDK. It is this tutorial example has inspired me for this approach.
http://devcenter.kinvey.com/ios/tutorials/bl-using-collection-hooks-effectively
A feature of the app we develop has a similar reservation use case. So this code from the tutorial returns a message
// If no rooms found, End the request without saving, // with a message of "no room available"
if (!result._id) { response.body = {message: "No Rooms Available"};
response.complete(); // completes the request and returns the result to the client
}
The question is how do you extract this message on the client side if the object is not saved as is the case in this example. I totally understand the usual case when the object is saved.
Thank you,
Mark
Pranav J
In your collection->PreSave hook(), you can handle the condition as an error condition as below:
In your iOS code, you can retrieve the error message using localizedFailureReason:
Let me know if it works for you.
Thanks,
Pranav
Kinvey Support
Mark L
Hi Pranav,
I think it is a good enough solution and should work for us although we may or may not have to check for a real error in the message, not sure at this point.
Thanks
Mark
.
-
How do I access query string values for GET and DELETE requests?
-
Basic Authentication in Business Logic
-
How do I cascade delete entities from related collections?
-
All BL failing with Violation Error
-
How do I send push notifications?
-
Whenever I try to query by _id, I get zero results
-
receiving SOCKETTIMEDOUT when requesting external http response
-
Unique Constraints on a collection column?
-
Need some help with grouping
-
Accessing Endpoint from Collection Hook
See all 342 topics