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

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
4 changes: 2 additions & 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,11 @@
"idRanges": [
{
"from": 2350,
"to": 2361
"to": 2362
}
],
"target": "OnPrem",
"runtime": "12.0",
"runtime": "14.0",
ajkauffmann marked this conversation as resolved.
Show resolved Hide resolved
"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,6 +6,7 @@ namespace System.RestClient;

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

Expand All @@ -14,6 +15,6 @@ codeunit 2360 "Http Client Handler" implements "Http Client Handler"
ResponseMessage: HttpResponseMessage;
begin
Success := HttpClient.Send(HttpRequestMessage.GetHttpRequestMessage(), ResponseMessage);
HttpResponseMessage.SetResponseMessage(ResponseMessage);
HttpResponseMessage := HttpResponseMessage.Create(ResponseMessage);
end;
}
Loading
Loading