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,
there is a video which look usefull for your case: Use case: CoinMarketCap API Integration - DataMiner Dojo
- What parameters do I need to capture from the API response?
- You need at least one param for the response and another one for the Response Status Code
- How should I structure error logging and handling?
- This depends on how you response data is structured a what do you need out of it
- What’s the best way to handle this in a QAction or a trigger?
- When you receive the response this can trigger a QAction, inside the QAction you Get the parameters where Status Code and Response are stored into variables
- Then you could work like if (statuscode != 200) to handle error response separately from normal responses
- If you have e.g. JSON data in your response you could desiralize it with Newtonsoft.Json
- Then you could store parts of the response you need in parameters of your choice
- you could store it into a code and a message param, also could split the message into multiple params
- yoiu could store it in a table to store every errored request (dont forget a cleaning mechanism to not have a endless growing table)
- dont forget to clean status code and response parameters after response, as the QAction will not triggered again if you have exactly the same response+status code, e.g.:
- protocol.CheckTrigger(123); in your response (123 is an example which id yur trigger has
- trigger id 123 type action and content is the id of the action
- action 123 with <On id="59;60" (your parameter ids to clear)>parameter</On><Type>clear</Type>
- Should I create a dedicated error-handling QAction?
- You should work at least with try/catch blocks to write QAction errors in the element log file, the rest depends on your needs