bcquality/microsoft/knowledge/web-services/format-exchanged-values-with-standard-format-9.bad.al
demiliani 570e776a37 Add data handling and test isolation guidance
- add SCM guidance for deriving base quantities through line unit-of-measure validation`n- add security guidance for parameterizing SetFilter with external text`n- add test isolation guidance for resetting per-test state before initialization guards`n- add web-service guidance for JSON null handling and invariant standard format 9`n- route and cover all five rules with paired evaluation fixtures
2026-09-23 17:09:24 +02:00

27 lines
1.2 KiB
AL

codeunit 50171 "Exchange Rate Export Bad"
{
procedure SendRate(CurrencyCode: Code[10]; StartingDate: Date; ExchangeRate: Decimal)
var
Client: HttpClient;
Response: HttpResponseMessage;
RequestUrl: Text;
begin
RequestUrl := StrSubstNo(RateUrlTok, CurrencyCode, Format(StartingDate), Format(ExchangeRate));
if not Client.Get(RequestUrl, Response) then
Error(RequestFailedErr);
if not Response.IsSuccessStatusCode() then
Error(RateRejectedErr, Response.HttpStatusCode());
end;
procedure ReadRate(RateText: Text) ExchangeRate: Decimal
begin
if not Evaluate(ExchangeRate, RateText) then
Error(InvalidRateErr, RateText);
end;
var
RateUrlTok: Label 'https://rates.example.com/rates?currency=%1&date=%2&rate=%3', Locked = true;
RequestFailedErr: Label 'The exchange rate service could not be reached.';
RateRejectedErr: Label 'The exchange rate service rejected the rate. Status code: %1.', Comment = '%1 = HTTP status code';
InvalidRateErr: Label 'The exchange rate %1 is not a valid decimal number.', Comment = '%1 = received value';
}