-
Notifications
You must be signed in to change notification settings - Fork 21
Description
I'm using the asynchronous conversion mode and I'm using the convertpi.client.get method to poll the conversion result.
I'm polling the results only after receiving the webhook confirmation, understanding that the conversion process would have been successful in this case.
For some reason, when polling results from the API after the webhook confirmation, I'm getting a response different than 200 OK. These are the possible status codes:
- 200 Conversion is successful. Response is a conversion result.
- 202 Conversion in progress.
- 404 JobId is invalid or response is expired.
- 503 No concurrent poll requests are allowed..
- 5XX Conversion error. Response is an error message.
I mostly get 200 OK responses when polling after the confirmation, but there are cases where I get a 202 Accepted with blank content. I suppose I'm hitting the API too fast and there is some internal propagation still ongoing, but that is not the point anyway, I could simply retry it and it will work.
The problem is that, since the response content is a blank string, and since the get method uses the handle_response method to convert the response to JSON or raise an exception, I'm hitting the unexpected exception json.decoder.JSONDecodeError.
The other error responses would raise_for_status and fail legitimely. The only problem is with the 202 response, that is a successful status (so it is not raised), but can't be returned as json. I wrote a small wrapper to solve this at my side:
def poll_retrieve(job_id):
convertapi.api_secret = settings.CONVERT_API_SECRET
response = requests.get(
convertapi.client.url(f"job/{job_id}"),
headers=convertapi.client.headers(),
timeout=convertapi.timeout or None,
)
response.raise_for_status()
if response.status_code == 202:
raise ConversionInProgressError
return response.json()
I could write a pull request, but I want to discuss with you the best approach first: is a new exception (like this ConversionInProgressError) a good idea? Or do you think returning a blank list would work better?