SugarREST API returns a entry_list even when the record is not found
Calling the REST API get_entry for a record that does not exist, I would expect that the service returns a fault instead of a entry_list. See example shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
{ entry_list: [ { id: "bf700a80-6cdf-6587-d548-4d2d74f47d6", module_name: "Contacts", name_value_list: [ { name: "warning", value: "Access to this object is denied since it has been deleted or does not exist" }, { name: "deleted", value: "1" } ] } ], relationship_list: []} <strong> </strong> |
Source 1. JSON returned when th record is not found.
My proposal is that the service returns a fault when the event occurs: records not found. See the example of the desired fault follows.
1 2 3 4 5 |
{ name: "Record not found or deleted", number: $error_number, description: "<code>Access to this object is denied since it has been deleted or does not exist</code>" } |
Source 2. Desired fault when record not found or deleted.
Managing abnormal situations through fault messages, simplifies error handling client side. See the output of a Java client Rest in case of error in the login process.
Following is an example of Java code that implements a client Rest managing all the fault the same way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
try {</code> SugarCRMInterface crmRestIf = new SugarCRMRestClient(); <code>// Try login <code> System.out.println("Try login..."); <code>UserAuthLogin userAuth = new UserAuthLogin( new UserAuth("wil","18218139eec55d83cf82679934e5cd75","1.0")); <code>EntryValue response = crmRestIf.login(userAuth, "RESTFulClient-1.0", null); ... // Get entry <code>System.out.println("Get entry..."); <code>EntryResult contact = crmRestIf.getEntry(response.getId(), "Contact", "bf700a80-6cdf-6587-d548-4d2d74f47d6c", null, null); ... } catch (FaultException fex) { <code>System.out.println("Code: " + Integer.toString(fex.getCode())); <code>System.out.println("Descrition: " + fex.getDescription()); <code>System.out.println("Detail: " + fex.getDetail()); <code>System.out.println("Detail Message: " + fex.getMessage()); }</code><em><strong> </strong></em> |
Source 3. Example of Java code that handles situations Fault.
The reference version is the 6.1 Community Edition, version 3 of the REST API.