AnsweredAssumed Answered

Custom API error message

Question asked by Daniel Alexander Montoya Herrera on Jun 5, 2020
Latest reply on Jun 5, 2020 by Daniel Alexander Montoya Herrera

Hello to everybody,

 

 

We need to control that some fields of type text only has numeric values (not ask why...) at both UI and API request level so when a regular user creates/edit a record and save it a popup tell them that they enter non numeric values on a filed and at the same time for any integrations for that module if they send non numeric values on a field, they/it will get(s) an error about it, the most important thing is that sugar don't let them create/save the changes to the DB and tell the user the error so they can fix it to try saving again.

 

 

Our aproch is to use a before_save logic hook that validates the fields and throw a new exeption if the validation fails.

 

It works as expected on sugar 9 or older but on sugar 10 it show a new popup too that confuse the users (UI) witht he message "here was an error while connecting to the server".

 

Also, I did try with other HTTP error codes but sugar UI only show my custom message to the user with error code 422, if I use 404 as the documentation example says, I only get on the UI an error "here was an error while connecting to the server".

 

 

On sugar 10 (any version) the expected behavior is that only the custom message popup on the UI, but a generic message popup on top of the custom one, if the validation on code is ok, both popup message disappears. So it is more of a cosmetic issue since it doesn't affect functionalility.

 

 

 

Now the question to the forum/comunity is how can I avoid that popup message on the UI ("here was an error while connecting to the server")?

 

Sugar documentation on how to get a custom error message from the api that also pupup on the UI preventing saving.

 

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.2/Integration/Web_Services/REST_API/API_Exceptions/ 

 

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Integration/Web_Services/REST_API/API_Exceptions/ 

 

I'm attaching what the UI presents and an example code that yuo can use or check that, on creating/editing a contact if you enter as a last_anem the value "custom" you will get a popup mesage using the documentatio on the documentation link example but if you enter last_name value of "outOfTheBox", you will get a popup message using a native class that also uses a 422 error code. In both cases (custom/native) you will get the custom message plus the "here was an error while connecting to the server" one.

 

 

both popup message and api response

 

 

Outcomes