getURLContentAsync throwing exception on non-200 success response [#16757]

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: getURLContentAsync throwing exception on non-200 success response [#16757]

Re: getURLContentAsync throwing exception on non-200 success response

by Ludek » Mon Jun 29, 2020 9:21 am

Thanks for reporting, I can replicate using:

Code: Select all

app.utils.web.getURLContentAsync('https://httpstat.us/204');
To be fixed as https://www.ventismedia.com/mantis/view.php?id=16757

getURLContentAsync throwing exception on non-200 success response [#16757]

by TIV73 » Sat Jun 27, 2020 3:28 am

Hi,
I have a local webservice. If the webservice is queried via get request and doesn't have any content for the request, it responds with http 204 - No Content (and no content). For reference, if I'm using invoke-webrequest to access the service, I get this:

Code: Select all

Invoke-WebRequest -Uri $url

StatusCode        : 204
StatusDescription : NoContent
Content           : {}
RawContent        : HTTP/1.1 204 NoContent
                    Date: Sat, 27 Jun 2020 08:21:37 GMT
                    Server: Kestrel
                    Content-Length: 0

Headers           : {[Date, System.String[]], [Server, System.String[]], [Content-Length, System.String[]]}
RawContentLength  : 0
RelationLink      : {}
I'm not sure if this is intentional or not, but it seems like getURLContentAsync doesn't handle this all too well. I'm using the code below:

Code: Select all

let headers = newStringList();
headers.add('Content-Type: application/json');

try {
  let response = await app.utils.web.getURLContentAsync(requestUrl, {
	headers: headers
  });
  let parsedResponse = JSON.parse(response);
} catch (error) {
  console.log('Error: ' + error.response)
}
The output I get from running this
Error: Access violation at address 0133566A in module 'MediaMonkeyEngine.exe'. Read of address 00000000

I was also able to reproduce this by using promises instead of async with some code I borrowed from lyricsSearch.js:

Code: Select all

var downloadPromise = app.utils.web.getURLContentAsync(requestUrl, {
  headers: headers
});
downloadPromise.then(function (Content) {
  console.log('succeeded ' + Content.response)
}, function (Content) {
  console.log('failed ' + Content.response)
}).catch(err => {
  console.log('err ' + err)
});

And the output I get:
failed Access violation at address 0133566A in module 'MediaMonkeyEngine.exe'. Read of address 00000000
Is there another way to handle these kind of requests, or is this intended behavior?

Top