Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rest Client] Support for Cookies + Fix secret headers + Collectible errors #2474

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/System Application/App/Rest Client/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
"idRanges": [
{
"from": 2350,
"to": 2361
"to": 2362
}
],
"target": "OnPrem",
"runtime": "12.0",
"resourceExposurePolicy": {
"allowDebugging": true,
"allowDownloadingSource": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.RestClient;

codeunit 2361 "HttpAuthOAuthClientCredentials" implements "Http Authentication"
{
Access = Public;
InherentEntitlements = X;
InherentPermissions = X;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.RestClient;
/// <summary>Implementation of the "Http Authentication" interface for a anonymous request.</summary>
codeunit 2358 "Http Authentication Anonymous" implements "Http Authentication"
{
Access = Public;
InherentEntitlements = X;
InherentPermissions = X;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using System;

codeunit 2359 "Http Authentication Basic" implements "Http Authentication"
{
Access = Public;
InherentEntitlements = X;
InherentPermissions = X;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.RestClient;

/// <summary>
/// This enum contains the exceptions of the Rest Client.
/// </summary>
enum 2351 "Rest Client Exception"
{
/// <summary>
/// Specifies that the exception is an unknown exception.
/// </summary>
value(100; UnknownException)
{
Caption = 'Unknown Exception';
}
/// <summary>
/// Specifies that the connection failed.
/// </summary>
value(101; ConnectionFailed)
{
Caption = 'Connection Failed';
}
/// <summary>
/// Specifies that the request is blocked by the environment.
/// </summary>
value(102; BlockedByEnvironment)
{
Caption = 'Blocked By Environment';
}
/// <summary>
/// Specifies that the request failed.
/// </summary>
value(103; RequestFailed)
{
Caption = 'Request Failed';
}
/// <summary>
/// Specifies that the content is not valid JSON.
/// </summary>
value(201; InvalidJson)
{
Caption = 'Invalid Json';
}
/// <summary>
/// Specifies that the content is not valid XML.
/// </summary>
value(202; InvalidXml)
{
Caption = 'Invalid Xml';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.RestClient;

codeunit 2362 "Rest Client Exception Builder"
{
ajkauffmann marked this conversation as resolved.
Show resolved Hide resolved
Access = Public;
InherentEntitlements = X;
InherentPermissions = X;

/// <summary>
/// Creates an exception with the specified error code and message. The exception is collectible if the errors are currently being collected.
/// </summary>
/// <param name="RestClientException">The error code for the exception.</param>
/// <param name="ErrorMessage">The message for the exception.</param>
/// <returns>The exception with the specified error code and message.</returns>
procedure CreateException(RestClientException: Enum "Rest Client Exception"; ErrorMessage: Text) Exception: ErrorInfo
begin
Exception := CreateException(RestClientException, ErrorMessage, IsCollectingErrors());
end;

/// <summary>
/// Creates an exception with the specified error code, message, and collectible flag.
/// </summary>
/// <param name="RestClientException">The error code for the exception.</param>
/// <param name="ErrorMessage">The message for the exception.</param>
/// <param name="Collectible">Whether the exception is collectible.</param>
/// <returns>The exception with the specified error code, message, and collectible flag.</returns>
procedure CreateException(RestClientException: Enum "Rest Client Exception"; ErrorMessage: Text; Collectible: Boolean) Exception: ErrorInfo
begin
Exception.Message := ErrorMessage;
Exception.CustomDimensions.Add('ExceptionCode', Format(RestClientException.AsInteger()));
Exception.CustomDimensions.Add('ExceptionName', RestClientException.Names.Get(RestClientException.Ordinals.IndexOf(RestClientException.AsInteger())));
Exception.Collectible := Collectible;
end;

/// <summary>
/// Gets the exception code from the error info.
/// </summary>
/// <param name="ErrInfo">The error info of the exception.</param>
/// <returns>The exception code.</returns>
procedure GetRestClientException(ErrInfo: ErrorInfo) RestClientException: Enum "Rest Client Exception"
var
ExceptionCode: Integer;
begin
Evaluate(ExceptionCode, ErrInfo.CustomDimensions.Get('ExceptionCode'));
RestClientException := Enum::"Rest Client Exception".FromInteger(ExceptionCode);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ namespace System.RestClient;

codeunit 2360 "Http Client Handler" implements "Http Client Handler"
{
Access = Public;
InherentEntitlements = X;
InherentPermissions = X;

procedure Send(HttpClient: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean;
procedure Send(CurrHttpClientInstance: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean;
var
ResponseMessage: HttpResponseMessage;
begin
Success := HttpClient.Send(HttpRequestMessage.GetHttpRequestMessage(), ResponseMessage);
HttpResponseMessage.SetResponseMessage(ResponseMessage);
Success := CurrHttpClientInstance.Send(HttpRequestMessage.GetHttpRequestMessage(), ResponseMessage);
HttpResponseMessage := HttpResponseMessage.Create(ResponseMessage);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace System.RestClient;

interface "Http Client Handler"
{
procedure Send(HttpClient: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean;
procedure Send(CurrHttpClientInstance: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean;
}
Loading
Loading