Hello Everyone,
I am currently developing my first driver, and I need some help with handling errors in my HTTP-based protocol. The API documentation defines an error response schema with only two parameters:
code
(integer, optional)message
(string, optional)
However, there is no specific description of what these error codes or messages represent. Additionally, the default error response is labeled as "Invalid request" without further details.
My Questions:
-
How should I define this error structure in my protocol?
- What parameters do I need to capture from the API response?
- How should I structure error logging and handling?
-
How should I implement this in my protocol (from parameter to trigger to QAction)?
- What’s the best way to handle this in a QAction or a trigger?
- Should I create a dedicated error-handling QAction?
Any guidance on how to structure this properly would be greatly appreciated. Thanks in advance!
Hi Deema,
- How should I define this error structure in my protocol?
- What parameters do I need to capture from the API response?
- the code to check if it is a valid http call and the content/error message
- How should I structure error logging and handling?
- you could display the error message via the protocol.log (if using a qaction) alternatively could set an exception value to the parameter that the api response is updating
- What parameters do I need to capture from the API response?
- How should I implement this in my protocol (from parameter to trigger to QAction)?
- What’s the best way to handle this in a QAction or a trigger?
-
if you are already going to process the response in a QAction, you could check the HTTP code there. Since we do not know what is the HTTP code, you could test it by trying to send an invalid request to the device to check the HTTP code that it gives.
Alternatively you could also to process the response only if your HTTP code is '200'
if you are not going to process the response in a qaction, you could have an after trigger with a condition to check if you got an error and do any follow up action like setting an exception value to a parameter
-
if you are already going to process the response in a QAction, you could check the HTTP code there. Since we do not know what is the HTTP code, you could test it by trying to send an invalid request to the device to check the HTTP code that it gives.
- Should I create a dedicated error-handling QAction?
-
- you could create a generic error handling in the precompile QA to share code which would allow you to reduce duplicate code to process exceptions for other http calls
-
- What’s the best way to handle this in a QAction or a trigger?
I hope these answers help