Forum Discussion

peterlu's avatar
peterlu
Champion
7 years ago

API v1 response - not well designed in Freemarker

Hi Lithium,

 

Sometimes, using rest() function in freemarker can throw an exception. But in some case, we do not want it to throw exception, but instead, we want to fetch information in this format below.

<response status="error">
<error code="100">
<message>
score.flood: You cannot give more than 1 Likes per day.
</message>
</error>
</response>
 
So we can use code like this
<#if res.@status == "error">
 
instead of
<#attempt>
......
<#recover>
${.error}
</#attempt>
 
Because ${.error} is a full stack trace which contains ugly message like "xxxx.ftl line 201, column 12....."
 
In some cases, we need to fetch message in clean xml format, so we can write some logic to send user proper messages.
 
Eg. If I want to write my own kudo function via rest API, I need to know if it fails due to kudo flood control, instead of a exception stack trace.
 
we are currently usng
rest("/messages/id/${messageId}/kudos/give")
Do we need to add something like ?restapi.response_style=xml to make it work? I have tried several, not working.
 
Peter
No RepliesBe the first to reply