doHTTPRequest error response

 

Good day

I am working with an integration with Redmine through REST API. I am create an issue in Redmine with doHTTPRequest("POST", url, headers, xml, 5, 5, 5, respHeaders) method. If an issue data is not valid, redmine returns 422 error code and the response:
<?xml version="1.0" encoding="UTF-8"?>
<errors type="array">
<error>Project field can't be blank</error>
</errors>

But in SM I'm getting only error:
"Error calling method: doHttpRequest in class: com/hp/ov/sm/server/utility/HttpClient Exception (java.io.IOException: Server returned HTTP response code: 422 fo
r URL: https://test.srv.ru/issues.xml)"

How can I get xml response in that case in SM?

Thank you for your help!

Top Replies

  • 0  

    Do you want get such response in SM.LOG

    So may be you need set  -debugnode:1 in sm.cfg

    But what do you do next with this log?

  • 0   in reply to ALARMus

    Good day,

    I need to receive this xml error response in order to show an information from it to current user in SM (for example, "Project field can't be blank")

    Thank you for your help.

  • 0   in reply to Aerika

    I assume you are doing this with JavaScript?  Can you attach your JavaScript you are using to invoke the REST API or web service call?

  • 0  

    This is a "known feature".
    If you're using an external RESTful API, it's not possible to receive reponses with a http code != 200.

    I have checked the JAVA Class and in case, that the response is an 400 or something like that, the reponse will be converted to an String (as you can see ;) ).

    Possible Workarounds:

    • Use the SOAP API
    • Use a middleware, which converts the 400 to an 200
    • Replace the response text and based on the http code, you can say "422 - Validation failed" or so.. not very helpful, but better than nothing ;)

     

    Btw. If you're trying to call the HPSM RESTful API from the HPSM itself, you can modify the "RestfulConstant" to get the error responses (but it's the dirty way ;) )

     

  • 0   in reply to MigrationDeletedUser

    Hi folks,

    Has this ever been fixed? I'm still having this issue with BMC. Consuming a CreateIssue WS and any time some validation fails I cannot extract the error message, because it's just 500. That's it.

    Come on people MF SM is here since...... restful since... Still nobody at HP/MF thought about "hmmm... maybe our system should be able to interpret http error messages"

    I mean I get it... some loonatic wrote it this way about 3000 years ago, fine... But wouldn't it be time to fix this?

    Please let me know if I'm banging on an open door...

    This hurts.