← ClaudeAtlas

csharp-error-handlinglisted

Handle errors from the PayPal Server SDK C# SDK. Load before your first try/catch around a call, or when building an error-translation layer. The thrown type won't tell you the status code is on `ResponseCode`, which failures never arrive as an `ApiException` at all, or that a Polly timeout does not derive from `OperationCanceledException`.
MuHamza30/paypal-api-plugin · ★ 0 · API & Backend · score 70
Install: claude install-skill MuHamza30/paypal-api-plugin
# Error handling for an APIMatic C# SDK Every error the API reports arrives as **`PaypalServerSdk.Standard.Exceptions.ApiException`** or a subclass of it, so one `catch (ApiException)` catches every *thrown* failure. `Exceptions/ApiException.cs` adds only a constructor and `ToString`; everything else comes from `CoreApiException<HttpRequest, HttpResponse, HttpContext>`, which extends `System.Exception` — so **the status code is `ResponseCode`**, not `StatusCode`. ## Which exception does an operation throw? Each operation declares its own error map, in the `ResponseHandler` block of its body: ```csharp .ResponseHandler(responseHandler => responseHandler .ErrorCase("404", CreateErrorCase("<the spec's description>", (errorReason, context) => new {Typed}Exception(errorReason, context))) .ErrorCase("0", CreateErrorCase("<the default-error description>", (errorReason, context) => new {Default}Exception(errorReason, context)))) ``` - Each documented status gets a **typed subclass** in `Exceptions/`, carrying the error schema's fields as `[JsonProperty]` auto-properties. - **`"0"` is the catch-all** for every other unsuccessful status; read which class it names, because an undocumented status does **not** imply the base `ApiException`. - With **no `"0"` case**, an unmapped status falls through to a plain `ApiException` carrying no payload, whose `Message` *starts* `HTTP Response Not OK`. Where a `"0"` case exists its description can itself be a t