mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 22:56:55 +01:00
Second contribution from CURABIS ApS, generalized from patterns observed across real AppSource/PTE development. Cross-checked against the current microsoft/knowledge corpus before opening; several originally-drafted candidates were dropped as duplicates of existing files.
24 lines
817 B
AL
24 lines
817 B
AL
codeunit 50101 "Sample Web Service Caller"
|
|
{
|
|
procedure CallExternalService()
|
|
var
|
|
ErrorLogEntry: Record "Sample Error Log";
|
|
begin
|
|
// BUG: the log write happens inside the same transaction as the
|
|
// risky call, using the same Record instance as the caller.
|
|
if not TryCallService() then begin
|
|
ErrorLogEntry.Init();
|
|
ErrorLogEntry."Error Message" := CopyStr(GetLastErrorText(), 1, 250);
|
|
ErrorLogEntry.Insert();
|
|
Error(GetLastErrorText());
|
|
// Error() above rolls back this transaction - including the
|
|
// Insert() just made. The failure is never actually logged.
|
|
end;
|
|
end;
|
|
|
|
[TryFunction]
|
|
local procedure TryCallService()
|
|
begin
|
|
// ... external call that may fail ...
|
|
end;
|
|
}
|