I have a cfhttp call that is running a basic GET r...
# lucee
d
I have a cfhttp call that is running a basic GET request to an API endpoint that simply returns a small data object (struct). If I hit the api endpoint directly in the browser it returns data every time with 200 status and data returned. However, when I try and call the endpoint using cfhttp() I occasionally see an error:
Copy code
string	key [filecontent] doesn't exist
To try and mitigate this occasional error I run the cfhttp in a while loop and give it up to 4 attempts to call the api. However, I still see the above error more often than should be possible. Is there anything I can do to further mitigate this issue - is there an issue with cfhttp?
b
@davla Put in some debgging and when filecontent doesn't exist, log out the rest of the cfhttp response. I assume the status code and status text will give you some clues
d
I occasionally see this as well:
Copy code
The key [filecontent] does not exist, only the following keys are available: [errordetail].
So I guess I need to output that error detail. The problem is that I can’t replicate the issue consistently to debug. I’ll have to add some extra debugging and then just wait and see.
b
Yep, you just gotta' add the debuggin, sit back, and wait for it to happen again
it's probably going to be some occasional network connectivity issue.
The ultimate fix will likely be for you to check the status code and if it's not
200 OK
, to not try and parse the response
Blindly parsing an HTTP response without checking the status code is already poor form because you're assuming the server was reachable and was able to process the request!
1
d
True, however it’s also our api and I know it’s responding with a 200 every time - I can see the requests in the logs on the API. I guess cfhttp is choking somewhere after that which I need to get to the bottom of - time to write a test case!
a
however it’s also our api and I know it’s responding with a 200 every time
If yer calling code can't reach yer API... it's not gonna get a 200OK.
☝️ 1
Blindly parsing an HTTP response without checking the status code
It's un-frickin-believable how much code I see that doesn't do this. I mean... the status code is there for a reason