UNPKG

@itwin/imodels-client-authoring

Version:

iModels API client wrapper for applications that author iModels.

66 lines 3.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IModelsErrorParser = void 0; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ const imodels_client_management_1 = require("@itwin/imodels-client-management"); class LocksErrorImpl extends imodels_client_management_1.IModelsErrorBaseImpl { objectIds; constructor(params) { super(params); this.objectIds = params.objectIds; } } class ConflictingLocksErrorImpl extends imodels_client_management_1.IModelsErrorBaseImpl { conflictingLocks; constructor(params) { super(params); this.conflictingLocks = params.conflictingLocks; } } class IModelsErrorParser extends imodels_client_management_1.IModelsErrorParser { static parse(response, originalError) { const errorFromApi = response.body; const errorCode = IModelsErrorParser.parseCode(errorFromApi?.error?.code); if (errorCode === imodels_client_management_1.IModelsErrorCode.NewerChangesExist) { const errorMessage = IModelsErrorParser.parseAndFormatLockErrorMessage(errorFromApi?.error?.message, errorFromApi?.error?.objectIds); return new LocksErrorImpl({ code: errorCode, message: errorMessage, originalError, objectIds: errorFromApi?.error?.objectIds, }); } if (errorCode === imodels_client_management_1.IModelsErrorCode.ConflictWithAnotherUser) { const errorMessage = IModelsErrorParser.parseAndFormatLockConflictErrorMessage(errorFromApi?.error?.message, errorFromApi?.error?.conflictingLocks); return new ConflictingLocksErrorImpl({ code: errorCode, message: errorMessage, originalError, conflictingLocks: errorFromApi?.error?.conflictingLocks, }); } return imodels_client_management_1.IModelsErrorParser.parse(response, originalError); } static parseAndFormatLockErrorMessage(message, objectIds) { let result = message ?? imodels_client_management_1.IModelsErrorParser._defaultErrorMessage; if (!objectIds || objectIds.length === 0) return result; result += ` Object ids: ${objectIds.join(" ,")}`; return result; } static parseAndFormatLockConflictErrorMessage(message, conflictingLocks) { let result = message ?? imodels_client_management_1.IModelsErrorParser._defaultErrorMessage; if (!conflictingLocks || conflictingLocks.length === 0) return result; result += " Conflicting locks:\n"; for (let i = 0; i < conflictingLocks.length; i++) { result += `${i + 1}. Object id: ${conflictingLocks[i].objectId}, lock level: ${conflictingLocks[i].lockLevel}, briefcase ids: ${conflictingLocks[i].briefcaseIds.join(", ")}\n`; } return result; } } exports.IModelsErrorParser = IModelsErrorParser; //# sourceMappingURL=IModelsErrorParser.js.map