286
Views
16
Comments
Solved
Error Code 422 Unprocessable Entity

Hello All and Happy New Year! Wish you all the best!

In my application i have a button and on clicking on it, then a API call(through post method) initiated. The Api call scope is to send an sms to the customer number(is static, not dynamical). Unfortunately, i got the below error.I check the error logs and i get the below


Any suggestion/idea?

TestSendSMS.oml
2018-10-29 08-31-03
João Marques
 
MVP
Solution

Have you tried to set the outputs of the server action in the Feedback Message action in Traditional Web?



OML of Traditional Web in attachment.

TestSendSMSWithExceptionHandlingTraditionalWeb.oml
2018-10-29 08-31-03
João Marques
 
MVP

Hi George,


Happy new year too!

Regarding your error, digging it here in older similar posts and could find these two that I think it may help you:

https://www.outsystems.com/forums/discussion/44721/422-unprocessable-entity-error/

https://www.outsystems.com/forums/discussion/53004/422-error-on-starting-my-application/


Can you take a look and see if the proposed solutions solve your situation?


Regards,

João

UserImage.jpg
George M

I have already check them but the issue in my case remains.

2018-10-29 08-31-03
João Marques
 
MVP

Hi George,


Have you checked if you have balance on your SMS.to account?

I was able to send an SMS and eventually ran out of balance and got the 422 Unprocessable Entity status code. See example below:




This is an API behavior, nothing to do with OutSystems itself.

You can also turn on the Full logging in Service Center (see here how) and you'll be able to see the full output of the web service and confirm all the details and error message.


Hope it helps.


Regards,
João

UserImage.jpg
George M

Thanks for your reply.
Let me know from which point you get the provided by you screen?

Also, i want to display different messages for every response code? Need to add any server action?

2018-10-29 08-31-03
João Marques
 
MVP

Hi George,


My screenshot was from the API call directly from PostMan, not going through OutSystems.

I built an OML that handles the exception and displays the error message in attachment.

In order to access the full details, you need first to turn on the full logging in Service Center.

To do that, you should access Service Center - Modules - enter the detail of your module TestSendSMS - tab Integrations - enter the detail of the API in question:


Then you need to turn the logging level to Full and choose the option Apply:


Then, after you execute the call in the browser which will generate the 422 Unprocessable Entity error, you can see the full detail of the API call through Service Center - Monitoring - Integrations and selecting the Error red message on the call:


Now you have access to the full request and response and can see the extra details:


Regards,
João

TestSendSMSWithExceptionHandling.oml
UserImage.jpg
George M

Thank you very much for the provided oml and for your support too.

How can i set to preview the return error or success code with the additional message with a feedback message?

Note my environment is traditional web.

2018-10-29 08-31-03
João Marques
 
MVP

Hi George,


Using Traditional Web or Reactive does not affect your approach on web service handling since they run on the server side.

When OutSystems detects an error HTTP status code (over 399), it will launch an exception and you will lose that context. But you can override this behavior using the OnAfterResponse, to "disguise" the service response as a HTTP code 200 to overcome the exception launched and enrich the output with the additional information. Note that this is additional work, you will need to check the output structure to understand if the service was OK (200) or not, and you would be using this approach at your own risk. 


You can read in more detail in the article How to Handle HTTP Status codes when consuming a REST API in OutSystems which also refers to the Forge component REST HTTP codes which showcases the aforementioned strategies.


Regards,
João

UserImage.jpg
George M

Thank you very much for the provided details. I would like to inform you that i follow the 2nd approach  but the error message is not displayed to user.

For example, i get successfully from the API the error code 422 but it is not displayed to user.

Any suggestion?

2018-10-29 08-31-03
João Marques
 
MVP

Hi George,


Have you followed the component example? I was able to put it to work without much effort following the aforementioned strategy.


The OML in attachment.


Regards,
João

TestSendSMSWithExceptionHandling.oml
UserImage.jpg
George M

Yes i have already follow your suggestion. My request is how to display the result of the api call through feedback message in traditional web.

2018-10-29 08-31-03
João Marques
 
MVP
Solution

Have you tried to set the outputs of the server action in the Feedback Message action in Traditional Web?



OML of Traditional Web in attachment.

TestSendSMSWithExceptionHandlingTraditionalWeb.oml
UserImage.jpg
George M

Hello João,

thank you for your effort. I study better and i understand the logic too.

One more question. The provider gives the feature of call back in order to inform me if the sms delivered or not, giving them a call back url. How can i implement it?
2018-10-29 08-31-03
João Marques
 
MVP

Hi George,


I am glad I could help. If you think the answer above solved your issue, please consider marking it as a solution so users with the same need can better find support.


Regarding your extra question, you want to implement the possibility of checking the status of the message is that it? It depends a lot on the use case. You would need to store the SMS's (or at least the Id) in an OutSystems entity, expose a REST webservice with the SMS Id as an input in order to receive the callback and mark the respective SMS as delivered.

Depending on the number of SMS's and traffic, you might want to think if OutSystems SQL Database is the best fit for this use case or if you should switch to an external NoSQL database that better handles high traffic tables. Data privacy is also something to think about it if your SMS's contains sensitive data or not.

As a recap, it depends on the use case and also on the services the external party allows to which I'm not familiar with.


Kind regards,
João

UserImage.jpg
George M

It is clear your approach. The API response has the below structure

{
    "message": "Message is queued for sending! Please check report for update",
    "success": true,
    "message_Id": "xxxxx"
}

How can i get only the "xxxxx" as part of response content?
UserImage.jpg
George M


It is clear your approach. The API response has the below structure

{

    "message": "Message is queued for sending! Please check report for update",

    "success": true,

    "message_Id": "xxxxx"

}


How can i get only the "xxxxx" as part of response content?

2018-10-29 08-31-03
João Marques
 
MVP

Hi George,


In order to fetch only the message_id field, you will need to have the API response to be a record of a structure with a field with JSON value message_id:


Take into account that the deserealization from the JSON to the structure is made via this field that by default assumes the structure attribute name.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.