All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.errors.cache-service-error-mapper.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheServiceErrorMapper = void 0;
const constants_1 = require("@grpc/grpc-js/build/src/constants");
const src_1 = require("../../src");
const errors_1 = require("@gomomento/sdk-core/dist/src/errors");
const sdk_core_1 = require("@gomomento/sdk-core");
class CacheServiceErrorMapper {
    constructor(throwOnError) {
        this.throwOnErrors = throwOnError;
    }
    returnOrThrowError(err, errorResponseFactoryFn) {
        const sdkError = normalizeSdkError(err);
        if (this.throwOnErrors) {
            throw sdkError;
        }
        else {
            return errorResponseFactoryFn(sdkError);
        }
    }
    resolveOrRejectError(opts) {
        const error = this.convertError(opts.err);
        if (this.throwOnErrors) {
            opts.rejectFn(error);
        }
        else {
            opts.resolveFn(opts.errorResponseFactoryFn(error));
        }
    }
    convertError(err) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j;
        const errParams = [
            (err === null || err === void 0 ? void 0 : err.message) || 'Unable to process request',
            err === null || err === void 0 ? void 0 : err.code,
            err === null || err === void 0 ? void 0 : err.metadata,
            err === null || err === void 0 ? void 0 : err.stack,
        ];
        switch (err === null || err === void 0 ? void 0 : err.code) {
            case constants_1.Status.PERMISSION_DENIED:
                return new src_1.PermissionError(...errParams);
            case constants_1.Status.DATA_LOSS:
            case constants_1.Status.INTERNAL:
            case constants_1.Status.ABORTED:
                return new src_1.InternalServerError(...errParams);
            case constants_1.Status.UNKNOWN:
                return new src_1.UnknownServiceError(...errParams);
            case constants_1.Status.UNAVAILABLE:
                return new src_1.ServerUnavailableError(...errParams);
            case constants_1.Status.NOT_FOUND: {
                let errCause = (_b = (_a = errParams[2]) === null || _a === void 0 ? void 0 : _a.get('err')) === null || _b === void 0 ? void 0 : _b[0];
                // TODO: Remove this once the error message is standardized on the server side
                const errorMessage = (_c = errParams[0]) === null || _c === void 0 ? void 0 : _c.toString();
                const isStoreNotFound = (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('Store with name:')) &&
                    (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes("doesn't exist"));
                // If errCause is not already set to 'store_not_found', check for store_not_found error
                if (!errCause && isStoreNotFound) {
                    errCause = 'store_not_found';
                }
                switch (errCause) {
                    case 'item_not_found':
                        return new errors_1.StoreItemNotFoundError(...errParams);
                    case 'store_not_found':
                        return new errors_1.StoreNotFoundError(...errParams);
                    default:
                        return new errors_1.CacheNotFoundError(...errParams);
                }
            }
            case constants_1.Status.OUT_OF_RANGE:
            case constants_1.Status.UNIMPLEMENTED:
                return new src_1.BadRequestError(...errParams);
            case constants_1.Status.FAILED_PRECONDITION:
                return new src_1.FailedPreconditionError(...errParams);
            case constants_1.Status.INVALID_ARGUMENT:
                return new src_1.InvalidArgumentError(...errParams);
            case constants_1.Status.CANCELLED:
                return new src_1.CancelledError(...errParams);
            case constants_1.Status.DEADLINE_EXCEEDED:
                return new src_1.TimeoutError(...errParams);
            case constants_1.Status.UNAUTHENTICATED:
                return new src_1.AuthenticationError(...errParams);
            case constants_1.Status.RESOURCE_EXHAUSTED: {
                const errCause = (_f = (_e = (_d = errParams[2]) === null || _d === void 0 ? void 0 : _d.get('err')) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.toString();
                return new src_1.LimitExceededError(...errParams, errCause);
            }
            case constants_1.Status.ALREADY_EXISTS: {
                let errCause = (_h = (_g = errParams[2]) === null || _g === void 0 ? void 0 : _g.get('err')) === null || _h === void 0 ? void 0 : _h[0];
                // TODO: Remove this once the error message is standardized on the server side
                const errorMessage = (_j = errParams[0]) === null || _j === void 0 ? void 0 : _j.toString();
                const isStoreAlreadyExists = (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('Store with name:')) &&
                    (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('already exists'));
                // If errCause is not already set to 'store_already_exists', check for store_already_exists error
                if (!errCause && isStoreAlreadyExists) {
                    errCause = 'store_already_exists';
                }
                switch (errCause) {
                    case 'store_already_exists':
                        return new sdk_core_1.StoreAlreadyExistsError(...errParams);
                    default:
                        return new sdk_core_1.CacheAlreadyExistsError(...errParams);
                }
            }
            default:
                return new src_1.UnknownError(...errParams);
        }
    }
}
exports.CacheServiceErrorMapper = CacheServiceErrorMapper;
function normalizeSdkError(error) {
    if (error instanceof src_1.SdkError) {
        return error;
    }
    return new src_1.UnknownError(error.message);
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGUtc2VydmljZS1lcnJvci1tYXBwZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZXJyb3JzL2NhY2hlLXNlcnZpY2UtZXJyb3ItbWFwcGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGlFQUF5RDtBQUV6RCxtQ0FjbUI7QUFDbkIsZ0VBSTZDO0FBSzdDLGtEQUc2QjtBQUU3QixNQUFhLHVCQUF1QjtJQUtsQyxZQUFZLFlBQXFCO1FBQy9CLElBQUksQ0FBQyxhQUFhLEdBQUcsWUFBWSxDQUFDO0lBQ3BDLENBQUM7SUFFRCxrQkFBa0IsQ0FDaEIsR0FBVSxFQUNWLHNCQUF5RDtRQUV6RCxNQUFNLFFBQVEsR0FBRyxpQkFBaUIsQ0FBQyxHQUFHLENBQUMsQ0FBQztRQUN4QyxJQUFJLElBQUksQ0FBQyxhQUFhLEVBQUU7WUFDdEIsTUFBTSxRQUFRLENBQUM7U0FDaEI7YUFBTTtZQUNMLE9BQU8sc0JBQXNCLENBQUMsUUFBUSxDQUFDLENBQUM7U0FDekM7SUFDSCxDQUFDO0lBRUQsb0JBQW9CLENBQUMsSUFBK0M7UUFDbEUsTUFBTSxLQUFLLEdBQUcsSUFBSSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUM7UUFFMU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KSB7XG4gICAgcmV0dXJuIGVycm9yO1xuICB9XG4gIHJldHVybiBuZXcgVW5rbm93bkVycm9yKGVycm9yLm1lc3NhZ2UpO1xufVxuIl19




© 2015 - 2025 Weber Informatics LLC | Privacy Policy