ContentstackException
ContentstackException
ContentstackException is the base exception for errors that the SDK raises itself, in the Contentstack.Management.Core.Exceptions namespace.
When to Use This Class: Catch it to handle every Open Authorization (OAuth) exception at once, or an unsupported parameter value in a ParameterCollection.
Conceptual Role: Acts as the parent of OAuthException and its subclasses. It extends System.Exception and adds no members.
Returns: ContentstackException. An SDK-side error.
Class-Level Notes
Not the API error type.
- The SDK throws ContentstackErrorException, not ContentstackException, when the API rejects a request. The two classes are unrelated, so catch (ContentstackException) does not catch an API rejection. See the ContentstackErrorException class page.
Where the SDK throws it.
- GetSortedParametersList throws it for a parameter value class the SDK does not support.
- The OAuth methods throw its subclass OAuthException. See the OAuthException class page.
Class-Level Properties
ContentstackException adds no properties. Read Message and InnerException from System.Exception.
Method Index
| Method Name | Returns | Description |
|---|---|---|
| ContentstackException | A new SDK exception. | Creates the exception with a message. |
Class-Level Snippet
This snippet catches API rejections and SDK-side OAuth errors in separate blocks during an OAuth token refresh.
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
OAuthHandler oauth = client.OAuth(new OAuthOptions() { AppId = "<APP_ID>", ClientId = "<CLIENT_ID>", RedirectUri = "<REDIRECT_URI>" });
try
{
await oauth.RefreshTokenAsync("<REFRESH_TOKEN>");
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}
catch (ContentstackException e)
{
// OAuthException and its subclasses extend ContentstackException
Console.WriteLine($"SDK error: {e.Message}");
}Methods
Each method of the ContentstackException class has its own section below, with its parameters, validation rules, behavior, and examples.
ContentstackException
ContentstackException creates an SDK exception with a message, and optionally the exception that caused it.
| Name | Type | Description |
|---|---|---|
| message (required) | string | Text that describes the error. |
| innerException (required) | Exception | The exception that caused this one. |
Returns: ContentstackException. A new SDK exception.
Overloads
- ContentstackException(string message)
- ContentstackException(string message, Exception innerException)
Validation
- There is no client-side validation. A null message falls back to the default text of System.Exception.
Behavior
- Client-side only. The constructor sends no request.
- Use it in tests or wrappers that need to raise the same exception type as the SDK.
Example
Basic usage: wrap an error from your own code
using System;
using Contentstack.Management.Core.Exceptions;
try
{
throw new ContentstackException("Content import failed.", new InvalidOperationException("<DETAILS>"));
}
catch (ContentstackException e)
{
Console.WriteLine($"{e.Message} ({e.InnerException?.Message})");
}