-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rest Client] Support for Cookies + Fix secret headers + Collectible …
…errors (#2474) <!-- Thank you for submitting a Pull Request. If you're new to contributing to BCApps please read our pull request guideline below * https://github.com/microsoft/BCApps/Contributing.md --> #### Summary <!-- Provide a general summary of your changes --> Adding support for cookies to the Rest Client Fixing an issue with secret headers Adding collectible error behavior Redesigning internal code for better maintainability and uptaking new AL features like the keyword `this` #### Work Item(s) <!-- Add the issue number here after the #. The issue needs to be open and approved. Submitting PRs with no linked issues or unapproved issues is highly discouraged. --> Fixes #1479 #989 Fixes [AB#560010](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/560010) --------- Co-authored-by: Jesper Schulz-Wedde <[email protected]>
- Loading branch information
1 parent
0e9b78e
commit 8f215cb
Showing
23 changed files
with
1,575 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/System Application/App/Rest Client/src/ExceptionHandling/RestClientException.Enum.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
... Application/App/Rest Client/src/ExceptionHandling/RestClientExceptionBuilder.Codeunit.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
{ | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.