Exceptions
The JavaScript SDK comes with custom exception classes for better error handling and abstracting certain implementation-specific exceptions.
All SDK exceptions should be serializable (they are marked Serializable
and override the Serializable
constructor). Furthermore, all SDK exceptions implement the three default Exception
constructors.
AuthenticationError
This exception is used for all authentication related errors. Note that this exception can happen at many places in the SDK, and is therefore not listed in the documentation of every method.
import { AuthenticationError } from "@sitecore/sc-contenthub-webclient-sdk/dist/errors/authentication-error";
try {
const client = new ContentHubClient(endpoint, oauth);
await client.internalClient.authenticateAsync();
}
catch (e) {
if (e instanceof AuthenticationError) {
// ..
}
}
ForbiddenError
This exception is used for all authorization related errors. Note that this exception can happen at many places in the SDK, and is therefore not listed in the documentation of every method.
import { ForbiddenError } from "@sitecore/sc-contenthub-webclient-sdk/dist/errors/forbidden-error";
if (e instanceof ForbiddenError) {
// ..
}
InternalError
The InternalError
is thrown when problems occur in the SDK and is usually a bug.
import { InternalError } from "@sitecore/sc-contenthub-webclient-sdk/dist/errors/internal-error";
if (e instanceof InternalError) {
// ..
}
NotFoundError
The NotFoundError
is thrown when a certain resource is required but cannot be found.
import { NotFoundError } from "@sitecore/sc-contenthub-webclient-sdk/dist/errors/not-found-error";
if (e instanceof NotFoundError) {
// ..
}
ValidationError
This exception is used for all validation related errors. For example, it is thrown when an object, such as an entity, is being persisted but does not pass the validation.
The ValidationError
's message can be useful to understand the reason behind it.
import { ValidationError } from "@sitecore/sc-contenthub-webclient-sdk/dist/errors/validation-error";
if (e instanceof ValidationError) {
// ..
}