Skip to content

Commit 49f0751

Browse files
committed
test
1 parent 8a82f2e commit 49f0751

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

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

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,81 @@ Details about errors are included as JSON in the response. Errors will be in thi
180180
181181
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.
182182
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 <xref:Microsoft.Xrm.Sdk.InvalidPluginExecutionException.#ctor(Microsoft.Xrm.Sdk.OperationStatus,System.Int32,System.String)> constructor. This allows you to pass an OperationStatus, a custom integer error code, and an error message.
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+
This response includes the following annotations:
248+
249+
250+
|Annotation |Value |Description |
251+
|---------|---------|---------|
252+
|`@Microsoft.PowerApps.CDS.ErrorDetails.OperationStatus`|`1`|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.|
253+
|`@Microsoft.PowerApps.CDS.ErrorDetails.SubErrorCode`|`12345`|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.|
254+
|`@Microsoft.PowerApps.CDS.HelpLink`|`http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException%3a80040265&client=platform`|A URL that contains information about the error which *may* re-direct you to guidance about how to address the error.|
255+
|`@Microsoft.PowerApps.CDS.TraceText`|`[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`|`Example Error Message.`|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.|
257+
184258

185259

186260

0 commit comments

Comments
 (0)