Hi,
actually (2.40) the HTTPRequest doesn't give back any information why the request failed.
In spider_HTTPRequest() there are three parameters in the $.ajax error:function(a,b,c) defined, but no-one is given back.
Looking in the docs, "b" gives back something like "timeout", "error", "abort" or "parsererror", and "c" gives back text http status like "Not Found" or "Internal Server Error."
For the callback to the SB program it is clear that the request was an error, when the first parameter is 0/#False, so the above error messages shouldn't be a problem when send as the second callback parameter. So maybe something like give back "c" when set, else give back "b"?
In the help it is written "The result of the request, as a text object", and an error message for me would be also a result.
HTTPRequest() please give back error message
Re: HTTPRequest() please give back error message
You can use the following workaround until then. Overwrite the SpiderBasic function and add the missing parameters to the callback:
Code: Select all
! spider_HTTPRequest = function (a, k, l, g, d, c) {
! "undefined" === typeof d && (d = 0);
! "undefined" === typeof c && (c = {
! map: {}
! });
! for (var f = Object.keys(c.map), h = {}, b = "GET", e = 0; e < f.length; e++)
! h[f[e]] = c.map[f[e]]._s;
! $.support.cors = !0;
! switch (a) {
! case 1:
! b = "POST";
! break;
! case 2:
! b = "PUT";
! break;
! case 4:
! b = "DELETE";
! break;
! case 3:
! b = "PATCH"
! }
! $.ajax({
! method: b,
! cache: !1,
! url: k,
! data: l,
! dataType: "html",
! headers: h,
! success: function (a) {
! g(1, a, d)
! },
! error: function (a, b, c) {
! g(0, "", d, a, b, c); // <- Here
! }
! })
! }
Procedure.s JSONstringify(JSONobject)
! return JSON.stringify(v_jsonobject);
EndProcedure
Procedure HttpGetEvent(Success, Result$, UserData, a, b, c)
If Success
Debug Result$
Else
Debug "HTTPRequest(): Error"
Debug "a: " + JSONstringify(a)
Debug "b: " + b
Debug "c: " + c
EndIf
EndProcedure
HTTPRequest(#PB_HTTP_Get, "NonExistingFileCausesFileNotFoundError", "", @HttpGetEvent())
Re: HTTPRequest() please give back error message
Peter, thanks for your direct solution, but much more for simply making this SB function readable for me. I think I will never get familiar with understanding such compressed spaghetti code, although programming for about 35 years in a lot of languages... But now it is readable and understandable, maybe I will try other things now!