If the following line:
postResult = SendSync("POST", serverURL, postTimeout)
generates this exception on a Windows server:
12029: Impossible d’établir une connexion avec le serveur
I try to catch the exception by using a try/catch structure, pause for a short time and then try again but it doesn’t work as the error does not appear to be cleared by the 2nd call as I hoped it would.
My class is based on the URLConnection with a method called to trigger the action:
Var serverURL, postResult As String
Var retryDelay, postTimeout As Integer
If DebugBuild Then
retryDelay = 20 // delai en secondes! pour tests!
postTimeout = 10 // temps en secondes d'attent de réponse au POST
Else
retryDelay = 300 // delai en secondes! pour laisser Planificateur de tâches le temps de relancer VHM_WebAPI
postTimeout = 120 // temps en secondes d'attent de réponse au POST
End If
serverURL = App.postServerURL
Try
postResult = SendSync("POST", serverURL, postTimeout)
If ResultError <> 0 And ResultError <> 401 Then
VHM_LogInfo(0, POSTBody.ToString)
VHM_LogInfo(0, ResultError.ToString + " – " + ResultErrorMessage)
End If
Return postResult
Catch err As RuntimeException
// MAC: -1004: Could not connect to the server. ==> SI VHM_WebAPI ne répond pas!!!
// WIN: 12029: Impossible d’établir une connexion avec le serveur
If err.ErrorNumber = -1004 Or err.ErrorNumber = 12029 Then
DelayMBS retryDelay
End If
End Try
Try
postResult = SendSync("POST", serverURL, postTimeout)
If ResultError <> 0 And ResultError <> 401 Then
VHM_LogInfo(0, POSTBody.ToString)
VHM_LogInfo(0, ResultError.ToString + " – " + ResultErrorMessage)
End If
Return postResult
Catch err1 As RuntimeException
// MAC: -1004: Could not connect to the server. ==> SI VHM_WebAPI ne répond pas!!!
// WIN: 12029: Impossible d’établir une connexion avec le serveur
If err1.ErrorNumber = -1004 Or err1.ErrorNumber = 12029 Then
Return "ERREUR RESEAU"
End If
End Try
The larger picture is that the POST is directed at a server that sometimes goes offline for a few minutes, never more than 5 minutes or a few seconds more. The timeout value is of no use as the exception occurs immediately.
The only solution I can think of would be to have all calls to this class handle the delay and fire off the request again, but this would require significant changes everywhere this occurs in the application.
Suggestions are clearly welcome. TIA.