import { ContainerErrorType , IGenericError , IErrorBase , IThrottlingWarning , } from "@fluidframework/container-definitions" ; import { LoggingError , isValidLegacyError , IFluidErrorBase , normalizeError , wrapError , wrapErrorAndLog , } from "@fluidframework/telemetry-utils" ; import { ITelemetryLogger , ITelemetryProperties } from "@fluidframework/common-definitions" ; import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions" ; /**
 * Generic wrapper for an unrecognized/uncategorized error object
 */ export class GenericError extends LoggingError implements IGenericError , IFluidErrorBase { readonly errorType = ContainerErrorType . genericError ; param errorMessage param error param props constructor ( readonly fluidErrorCode , readonly error ? , props ? ) { super ( fluidErrorCode , props , new Set ( [ "error" ] ) ) ; } } /**
 * Warning emitted when requests to storage are being throttled.
 */ export class ThrottlingWarning extends LoggingError implements IThrottlingWarning , IFluidErrorBase { readonly errorType = ContainerErrorType . throttlingError ; constructor ( message , readonly fluidErrorCode , readonly retryAfterSeconds , props ? ) { super ( message , props ) ; } /**
     * Wrap the given error as a ThrottlingWarning, preserving any safe properties for logging
     * and prefixing the wrapped error message with messagePrefix.
     */ static wrap ( error , errorCode , retryAfterSeconds , logger ) { const newErrorFn = ( errMsg ) => new ThrottlingWarning ( errMsg , errorCode , retryAfterSeconds ) ; return wrapErrorAndLog ( error , newErrorFn , logger ) ; } } /** Error indicating an API is being used improperly resulting in an invalid operation. */ export class UsageError extends LoggingError implements IFluidErrorBase { readonly errorType = "usageError" ; constructor ( readonly fluidErrorCode ) { super ( fluidErrorCode , { usageError : true } ) ; } } /** Error indicating that a client's session has reached its time limit and is closed. */ export class ClientSessionExpiredError extends LoggingError implements IFluidErrorBase { readonly errorType = "clientSessionExpiredError" ; constructor ( readonly fluidErrorCode , readonly expiryMs ) { super ( fluidErrorCode , { timeoutMs : expiryMs } ) ; } } export class DataCorruptionError extends LoggingError implements IErrorBase , IFluidErrorBase { readonly errorType = ContainerErrorType . dataCorruptionError ; readonly canRetry = false ; constructor ( readonly fluidErrorCode , props ) { super ( fluidErrorCode , { ... props , dataProcessingError : 1 } ) ; } } export class DataProcessingError extends LoggingError implements IErrorBase , IFluidErrorBase { readonly errorType = ContainerErrorType . dataProcessingError ; readonly canRetry = false ; constructor ( errorMessage , readonly fluidErrorCode , props ? ) { super ( errorMessage , props ) ; } param originalError param message param dataProcessingCodepath returns static wrapIfUnrecognized ( originalError , dataProcessingCodepath , message ? ) { const newErrorFn = ( errMsg ) => { const dpe = new DataProcessingError ( errMsg , "" ) ; dpe . addTelemetryProperties ( { untrustedOrigin : 1 } ) ; return dpe ; } ; const error = isValidLegacyError ( originalError ) ? normalizeError ( originalError ) : wrapError ( originalError , newErrorFn ) ; error . addTelemetryProperties ( { dataProcessingError : 1 , dataProcessingCodepath } ) ; if ( message !== undefined ) { error . addTelemetryProperties ( extractSafePropertiesFromMessage ( message ) ) ; } return error ; } } export const extractSafePropertiesFromMessage = ( message ) => ( { messageClientId : message . clientId , messageSequenceNumber : message . sequenceNumber , messageClientSequenceNumber : message . clientSequenceNumber , messageReferenceSequenceNumber : message . referenceSequenceNumber , messageMinimumSequenceNumber : message . minimumSequenceNumber , messageTimestamp : message . timestamp } ) ; /**
 * Conditionally coerce the throwable input into a DataProcessingError.
 */ export const CreateProcessingError = DataProcessingError . wrapIfUnrecognized ;