I have a codeunit method that is called on a trigger OnOpenPage() for the Purchase Order screen. It is a POST http request for a 3rd party web service and it works most of the time, but from time to time I get the error below. I have looked at tryfunction, but with that I cannot return a user defined value. I have tried other ways to use a global to get my return value but it doesn't seem to work exactly the way I need with tryfunction. If I didn't need to return a value this would work for me. What I'm trying to do is suppress the error or catch it so it won't throw an error on the open page. (In the old days like an On error resume next would work here for me.) I can't seem to find why or how to go about this. I've looked at retry logic to retry the http request on fail, but that doesn't seem to work as well. I still get the error. The error below, second error is when I put additional error handing to try to get more details. I know it isn't the url or any other issues with the request itself because as I said it works 95% of the time, and when it does throw the error, after exiting the screen and going back the same request works without error.
 
Error message: 
There was an error while executing the HTTP request, error request: ConnectionError. Make sure you are connecting to a valid endpoint.
 
Error message after additional error handling: 
HTTP request failed with status code 0: NavHttpClient Request Failed
 
Code for request:
    procedure getApplicationOn() enabled: Boolean
    var
        request: HttpRequestMessage;
        response: HttpResponseMessage;
        contentHeaders: HttpHeaders;
        content: HttpContent;
        jObj: JsonObject;
        jtext: Text;
        IsSuccessful: Boolean;
        responseText: Text;
    begin
        if (getExternAppName() = '') then begin
            error('App Name is empty.');
        end;
        if (getScreenTitle() = '') then begin
            error('Screen Title is empty.');
        end;
 
        globalJsonObj.WriteTo(jtext);
        // Add the payload to the content
        content.WriteFrom(jtext);
        // Retrieve the contentHeaders associated with the content
        content.GetHeaders(contentHeaders);
        contentHeaders.Clear();
        contentHeaders.Remove('Content-Type');
        contentHeaders.Add('Content-Type', 'application/json');
        request.Content := content;
        request.SetRequestUri(getApplicationURL() + '/api/Integration/GetEnabled');
        request.Method := 'POST';
        globalHttpClient.Send(request, response);
 
        if not response.IsSuccessStatusCode then begin
            enabled := false;
            exit;
        end;
 
        // pass true, no error so application active and ready
        enabled := true;
    end;