Question
When executing queries on REMOTES, we occasionally encounter gaps in the id numbering, which seemingly should be sequential. I need to understand why there are missing records. For example, in my case, there is no id 5167, 5163 in Totum. That is, the records were sent but not received.
We need to understand how to catch such errors.
Is this logged somewhere?
Is there any specific error message, or is it also a 200 OK and not tracked?
Answer
Most often, this effect can occur when several simultaneous requests are made, and they are written to one table. By default, tables have transaction restarts enabled in case of concurrent access errors ā with a remote request, there can be up to 5 restarts, after which it will return a 200 with an error content or (in some cases) an error message.
Since the id
of Totum is reserved at the start of the first attempt, it ends up being skipped.
If the remote completes successfully and you have the response type set to success/error
, then upon successful completion, it will be 200
+ success
.
In cases where you are continuously writing to a single table in Totum from an external system:
You need to exclude Action Codes in this table when adding and process the recorded rows asynchronously through setting flags with cron or daemons.
For this write table, set the "Relevance" parameter to ! Without tracking changes. In this case, the remote action code will not check the actions of other users in the table.
Use tryCatch in the remote code:
=catch: "remote_code_action_here"
catch: insert(table: 'table_for_errors'; field: 'data_field_for_error' = $#exception)
If you need to return headers, you should connect directly to remotes: HOST/Remotes/remote_name.
In this case, the remotes_user from which the remote will be executed is used, and authorization is passed either in the request body or in the header. You can read the headers in the remote code from the variable $#headers.
In this case, the response type set in the return field in the remote row in the remotes table works.
If you set the response option to headers + body in remotes, you can then form the headers you need:
=catch: json`{"headers":$headers_ok,"body":$body_ok}`
headers_ok: $#lc
body_ok: "code_action_here"
catch: json`{"headers":$headers_err,"body":$body_err}`
headers_err: json`["HTTP/1.0 500 Some custom error"]`
body_err: $#exception
Thus, we can provide the necessary error codes to an external service.