Display content on http requests returned with error status (400, 500)

10 views (last 30 days)
The content of web responses many times contain important information related to the error.
Fot the webread/webwrite functions an error is thrown for all responses with 400 or 500 status, with a generic error message. Is there a way to access the content of requests so that an error can be thrown with a more specific error message?

Answers (1)

Benjamin Kraus
Benjamin Kraus on 26 Dec 2017
What version of MATLAB are you using? The specifics of this behavior have changed a little over the past few releases.
Even with the most recent version of MATLAB, I do not think the webread and webwrite functions provide this capability. I skimmed through the documentation for the weboptions function, and did not see a mechanism for changing error handling. It looks like the only information you get is in the actual text of the error message.
However, starting in R2016b there is a low-level HTTP API that you can use to access more detailed information about the error codes. This low-level HTTP API can definitely provide the information you are looking for.
Check out this documentation page for more information: HTTP Interface

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!