/**
 * Represents the details associated with a  NetworkError .
  export interface INetworkErrorDetails { /**
     * Indicates whether this is an error that can be retried. Refer to  NetworkError . canRetry .
      canRetry ? : boolean ; /**
     * Indicates whether this error is fatal. This generally indicates that the error causes
     * negative, non-recoverable impact to the component/caller and cannot be ignored.
     * Refer to  NetworkError . isFatal .
      isFatal ? : boolean ; /**
     * Represents the message associated with the error. Refer to  NetworkError 's message.
      message ? : string ; /**
     * Represents the time in milliseconds that should be waited before retrying.
     * Refer to  NetworkError . retryAfterMs .
      retryAfter ? : number ; } remarks The Fluid Framework server implementation includes a collection of services that communicate with each other
 * over the network. Network communication is subject to a diverse range of errors.  NetworkError helps
 * convey more information than a simple HTTP status code, allowing services to be aware of the context of a
 * network error and making those services more prepared to react to such kinds of errors.
  export class NetworkError extends Error { constructor ( public public readonly code , public message , /**
     * Optional boolean indicating whether this is an error that can be retried.
     * Only relevant when  NetworkError . isFatal is false.
     *  public public readonly canRetry ? , public public readonly isFatal ? , public public readonly retryAfterMs ? ) { super ( message ) ; this . name = "NetworkError" ; } /**
     * Gets the details associated with this  NetworkError .
     *  returns A simple string conveying the message if no other details are included in this  NetworkError ,
     * or an  INetworkErrorDetails object otherwise.
     *  public public get details ( ) : INetworkErrorDetails | string { if ( this . canRetry === undefined && this . isFatal === undefined && this . retryAfterMs === undefined ) { return this . message ; } return { message : this . message , canRetry : this . canRetry , isFatal : this . isFatal , retryAfter : this . retryAfterMs } ; } } /**
 * Convenience function for generating a  NetworkError .
 *  remarks Generates a  NetworkError instance appropriately configured given the status code and error data
 * provided. This function is intended to be used in situations where a  NetworkError is dynamically created
 * based variable parameters. That is, when it is not known whether the status code can be 404 or 500.
 *  param statusCode param errorData - Optional additional data associated with the error. Can either be a simple string representing
 *  the message, or an  INetworkErrorDetails object.
 *  returns A  NetworkError instance properly configured according to the parameters provided.
 *  public export function createFluidServiceNetworkError ( statusCode , errorData ? ) { let message ; let canRetry ; let isFatal ; let retryAfter ; if ( errorData && typeof errorData === "object" ) { message = errorData . message ?? "Unknown Error" ; canRetry = errorData . canRetry ; isFatal = errorData . isFatal ; retryAfter = errorData . retryAfter ; } else if ( errorData && typeof errorData === "string" ) { message = errorData ; } else { message = "Unknown Error" ; } switch ( statusCode ) { case 401 : case 403 : case 404 : return new NetworkError ( statusCode , message , false , false ) ; case 422 : return new NetworkError ( statusCode , message , canRetry ?? false , isFatal ?? false , canRetry ? retryAfter : undefined ) ; case 429 : return new NetworkError ( statusCode , message , true , false , retryAfter ) ; case 500 : { return new NetworkError ( statusCode , message , canRetry ?? true , isFatal ?? false , canRetry ? retryAfter : undefined ) ; } case 502 : case 503 : case 504 : return new NetworkError ( statusCode , message , true , false , retryAfter ) ; default : return new NetworkError ( statusCode , message , false , true ) ; } } /**
 * Convenience function to both generate and throw a  NetworkError .
 *  remarks Similarly to  createFluidServiceNetworkError , this function generates a  NetworkError * instance appropriately configured given the status code and error data provided. The difference is that this
 * function also throws the  NetworkError .
 *  param statusCode param errorData - Optional additional data associated with the error. Can either be a simple string representing
 *  the message, or an  INetworkErrorDetails object.
 *  public export function throwFluidServiceNetworkError ( statusCode , errorData ? ) { const networkError = createFluidServiceNetworkError ( statusCode , errorData ) ; throw networkError ; }