ASSERTERROR BEGIN Response := Request.GetResponse(); IF (HttpWebStatus.Equals(Response.StatusCode,HttpWebStatus.OK)) THEN BEGIN ResponseStream := Response.GetResponseStream(); ERROR('OK'); END ELSE BEGIN HttpWebStatus := Response.StatusCode; ERROR(Response.StatusDescription); END; END; IF GETLASTERRORTEXT = 'OK' THEN BEGIN IF NOT ISNULL(ResponseStream) THEN BEGIN .....
Answers
Pseudo code:
IF NOT HttpWebRequest.GetResponse THEN ERROR('')
I don't know what you mean with 'proper response' but when a request is succesfull you normally receive a HTTP 200. This value is returned as reference through HttpStatusCode. You can test the StatusCode output to identify if the response is OK, Unauthorized, Internal Server Error, Bad Request etc.
Pseudo code:
if HttpStatusCode = 200 THEN
EXIT(True) ELSE // Success
ERROR('Something went wrong %1',HttpStatusCode); // Something went wrong
> The function GetResponse already returns a Boolean but I think you already know that. You could do something like:
>
> Pseudo code:
> IF NOT HttpWebRequest.GetResponse THEN ERROR('')
>
> I don't know what you mean with 'proper response' but when a request is succesfull you normally receive a HTTP 200. This value is returned as reference through HttpStatusCode. You can test the StatusCode output to identify if the response is OK, Unauthorized, Internal Server Error, Bad Request etc.
>
> Pseudo code:
> if HttpStatusCode = 200 THEN
> EXIT(True) ELSE // Success
> ERROR('Something went wrong %1',HttpStatusCode); // Something went wrong
It doesn't return a boolean, but HttpWebResponse object.
The HttpWebResponse.StatusCode can only be called after the HttpWebRequest.GetResponse call, which initializes the HttpWebResponse object.
But i am getting errors on HttpWebRequest.GetResponse call so i cannot check the status code at this point.
In NAV 2013 that don't have a try function I do something like this
Regards.
Please notice that an API can also return HTTP 201 for example. So only checking for OK is not (always) good enough.
THEN BEGIN
Thank you @ftornero this is very helpful
@irasoelbaks i am looking at this function
Please let me know, which GetResponse function you are talking about.
Yes you are right, but we can handle that in code
@irasoelbaks i think you are talking about GetResponse function in codeunit 1297 Http Web Request Mgt. but i am working on NAV 2013 and it doesn't have this codeunit and try functions.
Sorry my bad, i should have mentioned NAV version in my question
No problem. I meant Codeunit 1297 indeed.