Extract JSON from latestError when REST request fails

1
Hi, When the Java action request of the REST module gets a 400 or other error from the provider it fails with an error and in the latestError object the details are found. However, the provider might send JSON data to tell what is wrong. Now I get this in latestError.Message: 400. Rest request failed: [HTTP Request: POST 'https://my.url.domain.tld' --> Response status: 400 Bad Request, ETag: null, body: '{"succeeded":false,"reason":"You are not authorized"}'] I can parse the string and look for the data that I need and serialize it, but isn't there a simpler and more robust way? And the provider returns 400 but with JSON data, can't this be put in the RequestResult return of the Java action request? Regards, Paul
asked
1 answers
-1

If the response data is of consistent layout: You could search for the first '{' and copy from there into a string. Using the REST module, parse the string into a mendix object.

answered