API Timeout error handling

As part of script runs we use an API to log the execution in a Project Management tool. This is working fine. The issue I am having is when a timeout occurs, which is rare, but usually when the execution is happening on a client machine and network issues there. The request usually works (item is created) just no response (upping the timing doesn’t help so far and I don’t want to get to carried away with that). What is bothering me is that is of course an error and the script goes on and executes without issue but still shows as failed. I would like to get around this and have it be a success with just a warning. If we get a response back and its not a 200 status we just want to log those as a warning (for now) for the user to double check. How do I handle this error to make it a warning. Try/Catch wont work since not an exception but wasn’t sure if another way to catch the results of the API call and do some handling of when there is an error

I usually do a check after the API call to get information out of it and to check the response. something like:

	DAI_API(httpMethod:"POST",url:URL,requestBody:RB,requestheaders:RH) //I'm overwriting some of the API test settings in this case see https://docs.eggplantsoftware.com/studio/epf-api-running-tests/#example-1 for more info)
	
	if api().statusCode = "200" then
		Logsuccess "Able to Access DAI Server, and grab a access token"
		put JSONValue(api().responsebody) into ResponseInformation	
		put ResponseInformation.access_token into access_token
	else
		logerror "Unable to Access DAI Server (Bad Username,Password, or DAI Server)"
		logwarning ResponseInformation
		logwarning API()
	end if

So that is exactly what I am doing, the problem is this line
DAI_API(httpMethod:“POST”,url:URL,requestBody:RB,requestheaders:RH)

That is logging its own error. Would prefer it be an exception so I could wrap in a try catch block and do what I want with it and not cause it to show the script as failed when really the script ran fine (the core part we care about) and I could just store that API failure and do something else with it

Ah, I see. I think what I would do in that case would be to add a check in the API Script section. This is code that runs after the API response comes back or times out. As far as I know there is not any setting to throw an exception for API timeouts.

Something like:

You can use a check that the api()status code is not 0 (which I believe happens when the API times out. Or api()status code is 200 to catch any unsuccessful API calls.

I have tried this as well but the error happens before that code runs is the issue I am having. The Set Response line has ran in this case and timeout occurred so the error/test failure has already happened before I can check the statuscode.

It looks like this might be doable using the post command vs the API tests and changing the API error settings

	set the URLErrorLevel to 0
	set the throwExceptionResults to false
	
	post JSONformat(RB) to url URL with headers RH
	log it