UNPKG

@itwin/imodels-client-authoring

Version:

iModels API client wrapper for applications that author iModels.

62 lines 3.04 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { IModelsErrorBaseImpl, IModelsErrorCode, IModelsErrorParser as ManagementIModelsErrorParser, } from "@itwin/imodels-client-management"; class LocksErrorImpl extends IModelsErrorBaseImpl { objectIds; constructor(params) { super(params); this.objectIds = params.objectIds; } } class ConflictingLocksErrorImpl extends IModelsErrorBaseImpl { conflictingLocks; constructor(params) { super(params); this.conflictingLocks = params.conflictingLocks; } } export class IModelsErrorParser extends ManagementIModelsErrorParser { static parse(response, originalError) { const errorFromApi = response.body; const errorCode = IModelsErrorParser.parseCode(errorFromApi?.error?.code); if (errorCode === 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 === 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 ManagementIModelsErrorParser.parse(response, originalError); } static parseAndFormatLockErrorMessage(message, objectIds) { let result = message ?? ManagementIModelsErrorParser._defaultErrorMessage; if (!objectIds || objectIds.length === 0) return result; result += ` Object ids: ${objectIds.join(" ,")}`; return result; } static parseAndFormatLockConflictErrorMessage(message, conflictingLocks) { let result = message ?? ManagementIModelsErrorParser._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; } } //# sourceMappingURL=IModelsErrorParser.js.map