Exceptions

Current version: 3.3

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.

RequestResponse
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.

RequestResponse
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.

RequestResponse
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.

RequestResponse
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. TFor example, it is thrown when an object (e.g. an entity) is being persisted but does not pass the validation.

The ValidationError's message can be useful to understand the reason behind it.

RequestResponse
import { ValidationError } from "@sitecore/sc-contenthub-webclient-sdk/dist/errors/validation-error";

if (e instanceof ValidationError) {
    // ..
}

Do you have some feedback for us?

If you have suggestions for improving this article,