What's Cooking in Business Central: Cookies and Collectible Errors in the REST Client
Business Central REST client module additions: cookie support (set on requests, read from responses) and collectible errors with a REST client exception enum. Described as coming in the module version released with Business Central version 26.
- Cookie Support in REST Client Module
- Exception Handling Overview and Previous Behavior
- Collectible Errors and Error Collection Pattern
- REST Client Exception Enum and Try-Catch Pattern
Overview
The video covers two additions to the REST client module in Business Central, which the presenter says will be released with version 26. The first is cookie support: setting cookies on requests, reading them from responses, and working with cookie objects.
The second is collectible errors. With error collection enabled, the REST client throws collectible errors for problems such as connection failures, invalid JSON and HTTP errors. The code can then read the collected error and test an exception enum, which gets close to a try-catch pattern.
Key points
- The cookie support and error handling shown are in the next version of the REST client module, released with Business Central version 26.
- Set cookie on the request message takes either a cookie object or a cookie name and value. To set extra properties such as domain or secret, create a cookie object first. An existing cookie is replaced.
- The get cookie names function returns a list of cookie names in the response, so you can check whether a cookie was returned.
- If you get a cookie without checking the names first, you get an empty cookie when it does not exist. A try-get variant returns a Boolean that says whether the cookie exists.
- The get cookies function returns a full dictionary with cookie names as keys, which is more convenient than a list of names.
- Adding the error behavior line (error collection) to your function makes the REST client throw collectible errors instead of normal errors. Only one error is collected, because the client stops at the first failure.
- The REST client exception enum covers blocked by environment, connection failed, request failed (HTTP errors), invalid JSON, invalid XML and unknown errors.
Features
| Feature | Status | At | Evidence |
|---|---|---|---|
| Cookie Support in REST Client | announced, demoed | 0:06 | “in the next version of the rest client module that will be released with version 26 of business Central the rest client module now” (0:06) |
| Get Cookie Names Function | status not stated, demoed | 1:24 | |
| Get Cookies Dictionary Function | status not stated, demoed | 2:45 | |
| Collectible Errors in REST Client | status not stated, demoed | 4:33 | |
| REST Client Exception Enum | status not stated, demoed | 5:53 | |
| REST Client Exception Builder | status not stated, demoed | 5:53 |
AL objects mentioned
As heard in the captions. A name that matches one object page by exact type and name links to it; the others stay as named.
Quotes
- 0:06 “in the next version of the rest client module that will be released with version 26 of business Central the rest client module now”
- 1:04 “if you want to set some extra properties on the cookie like uh domain uh or Secrets then you have to create a cookie”
- 2:45 “get cookies so this uh is not justk returning a list of cookie names but gives you a full dictionary which I think uh”
- 4:33 “get collected errors so based on um this line of code you see here um where you enable um error collection”
- 5:13 “there will always be one error because uh it stops at the first failure is not going to try anything further because that doesn’t”
- 6:14 “you can test the enum um what is it was it blocked by environment uh was it the connection field request field which means”
- 6:34 “by um implementing this pattern you are actually getting close to what is known in CP code as the tri catch pattern”
Disclaimers in the video
- 0:06 coming-later: will be released with version 26 of business Central
