Skip to content

Commit df75be0

Browse files
authored
Merge pull request #3237 from MicrosoftDocs/master-jdaly-2020-8-9
Master jdaly 2020 8 9
2 parents 62b04dc + 8b63c90 commit df75be0

File tree

1 file changed

+87
-3
lines changed

1 file changed

+87
-3
lines changed

powerapps-docs/developer/common-data-service/webapi/compose-http-requests-handle-errors.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Compose HTTP requests and handle errors (Common Data Service)| Microsoft Docs"
33
description: "Read about the HTTP methods and headers that form a part of HTTP requests that interact with the Web API and how to identify and handle errors returned in the response"
44
ms.custom: ""
5-
ms.date: 04/03/2020
5+
ms.date: 08/09/2020
66
ms.service: powerapps
77
ms.suite: ""
88
ms.tgt_pltfrm: ""
@@ -152,7 +152,7 @@ Details about errors are included as JSON in the response. Errors will be in thi
152152
```
153153

154154
> [!IMPORTANT]
155-
> The structure of the error messages is changing. This change is expected to be deployed to different regions over a period starting in late April through May 2020.
155+
> The structure of the error messages is changing. This change is expected to be deployed to different regions over a period starting in August through October 2020.
156156
>
157157
> Before this change, the errors returned were in this format:
158158
>
@@ -176,7 +176,91 @@ Details about errors are included as JSON in the response. Errors will be in thi
176176
>
177177
> If you find that an application you use has a dependency on this property after this change is deployed, you can contact support and request that the change be temporarily removed for your environment. This will provide time for the application developer to make appropriate changes to remove this dependency.
178178
179-
179+
### Include additional details with errors
180+
181+
Some errors can include additional details using *annotations*. When a request includes the `Prefer: odata.include-annotations="*"` header, the response will include all the annotations which will include additional details about errors and a URL that can be used to be directed to any specific guidance for the error.
182+
183+
Some of these details can be set by developers writing plug-ins. For example, let’s say you have a plug-in that throws an error using the [InvalidPluginExecutionException(OperationStatus, Int32, String)](/dotnet/api/microsoft.xrm.sdk.invalidpluginexecutionexception.-ctor#Microsoft_Xrm_Sdk_InvalidPluginExecutionException__ctor_Microsoft_Xrm_Sdk_OperationStatus_System_Int32_System_String_) constructor. This allows you to pass an OperationStatus value, a custom integer error code, and an error message.
184+
185+
A simple plug-in might look like this:
186+
187+
```csharp
188+
namespace MyNamespace
189+
{
190+
public class MyClass : IPlugin
191+
{
192+
public void Execute(IServiceProvider serviceProvider)
193+
{
194+
195+
// Obtain the tracing service
196+
ITracingService tracingService =
197+
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
198+
199+
tracingService.Trace("Entering MyClass plug-in.");
200+
201+
try
202+
{
203+
throw new InvalidPluginExecutionException(OperationStatus.Canceled, 12345, "Example Error Message.");
204+
}
205+
catch (InvalidPluginExecutionException ex)
206+
{
207+
tracingService.Trace("StackTrace:");
208+
tracingService.Trace(ex.StackTrace);
209+
throw ex;
210+
}
211+
}
212+
}
213+
}
214+
```
215+
216+
When this plug-in is registered on the create of an account entity, and the request to create an account includes the `odata.include-annotations="*"` preference, the request and response will look like the following:
217+
218+
**Request**
219+
220+
```http
221+
POST https://yourorg.api.crm.dynamics.com/api/data/v9.1/accounts HTTP/1.1
222+
Content-Type: application/json;
223+
Prefer: odata.include-annotations="*"
224+
{
225+
"name":"Example Account"
226+
}
227+
228+
```
229+
230+
**Response**
231+
232+
```http
233+
HTTP/1.1 400 Bad Request
234+
Content-Type: application/json; odata.metadata=minimal
235+
{
236+
"error": {
237+
"code": "0x80040265",
238+
"message": "Example Error Message.",
239+
"@Microsoft.PowerApps.CDS.ErrorDetails.OperationStatus": "1",
240+
"@Microsoft.PowerApps.CDS.ErrorDetails.SubErrorCode": "12345",
241+
"@Microsoft.PowerApps.CDS.HelpLink": "http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException%3a80040265&client=platform",
242+
"@Microsoft.PowerApps.CDS.TraceText": "\r\n[MyNamespace: MyNamespace.MyClass ]\r\n[52e2dbb9-85d3-ea11-a812-000d3a122b89: MyNamespace.MyClass : Create of account] \r\n\r\n Entering MyClass plug-in.\r\nStackTrace:\r\n at MyNamespace.MyClass.Execute(IServiceProvider serviceProvider)\r\n\r\n"
243+
"@Microsoft.PowerApps.CDS.InnerError.Message": "Example Error Message."
244+
}
245+
}
246+
```
247+
248+
This response includes the following annotations:
249+
250+
|Annotation and Description |Value |
251+
|---------|---------|
252+
|`@Microsoft.PowerApps.CDS.ErrorDetails.OperationStatus`<br/>The value of the <xref:Microsoft.Xrm.Sdk.OperationStatus> set by the [InvalidPluginExecutionException(OperationStatus, Int32, String)](/dotnet/api/microsoft.xrm.sdk.invalidpluginexecutionexception.-ctor#Microsoft_Xrm_Sdk_InvalidPluginExecutionException__ctor_Microsoft_Xrm_Sdk_OperationStatus_System_Int32_System_String_) constructor.|`1`|
253+
|`@Microsoft.PowerApps.CDS.ErrorDetails.SubErrorCode`<br/>The value of the `SubErrorCode` set by the [InvalidPluginExecutionException(OperationStatus, Int32, String)](/dotnet/api/microsoft.xrm.sdk.invalidpluginexecutionexception.-ctor#Microsoft_Xrm_Sdk_InvalidPluginExecutionException__ctor_Microsoft_Xrm_Sdk_OperationStatus_System_Int32_System_String_) constructor.|`12345`|
254+
|`@Microsoft.PowerApps.CDS.HelpLink`<br/>A URL that contains information about the error which *may* re-direct you to guidance about how to address the error.|`http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException%3a80040265&client=platform`|
255+
|`@Microsoft.PowerApps.CDS.TraceText`<br/>Content written to the Plug-in trace log using the [ITracingService.Trace(String, Object[]) Method](/dotnet/api/microsoft.xrm.sdk.itracingservice.trace). This includes the stacktrace for the plugin because the plug-in author logged it.|`[MyNamespace: MyNamespace.MyClass ]`<br/>`[52e2dbb9-85d3-ea11-a812-000d3a122b89: MyNamespace.MyClass :Create of account]`<br/><br/>`Entering MyClass plug-in.`<br/>`StackTrace:`<br/>` at MyNamespace.MyClass.Execute(IServiceProvider serviceProvider)`|
256+
|`@Microsoft.PowerApps.CDS.InnerError.Message`<br/>The error message found in the InnerError for the exception. This should be the same as the error message except in certain special cases that are for internal use only.|`Example Error Message.`|
257+
258+
> [!NOTE]
259+
> The `@Microsoft.PowerApps.CDS.HelpLink` is not guaranteed to provide guidance for every error. Guidance *may* be provided proactively but most commonly it will be provided reactively based on how frequently the link is used. Please use the link. If it doesn't provide guidance, your use of the link helps us track that people need more guidance about the error. We can then prioritize including guidance to the errors that people need most. The resources that the link may direct you to may be documentation, links to community resources, or external sites.
260+
261+
If you do not want to receive all annotations in the response, you can specify which specific annotations you want to have returned. Rather than using `Prefer: odata.include-annotations="*"`, you can use the following to receive only formatted values for operations that retrieve data and the helplink if an error occurs:
262+
`Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue,Microsoft.PowerApps.CDS.HelpLink"`.
263+
180264
### See also
181265

182266
[Perform operations using the Web API](perform-operations-web-api.md)<br />

0 commit comments

Comments
 (0)