import StorageError from "./StorageError" ; const DefaultID = "DefaultBlobRequestID" ; export class export default class StorageErrorFactory { public static getContainerNotFound ( contextID = DefaultID ) { return new StorageError ( 404 , "ContainerNotFound" , "The specified container does not exist." , contextID ) ; } public static getRequestEntityTooLarge ( contextID = DefaultID ) { return new StorageError ( 413 , "RequestEntityTooLarge" , "The uploaded entity blob is too large." , contextID ) ; } public static getBlockCountExceedsLimit ( contextID = DefaultID ) { return new StorageError ( 409 , "BlockCountExceedsLimit" , "The committed block count cannot exceed the maximum limit of 50,000 blocks." , contextID ) ; } public static getContainerAlreadyExists ( contextID = DefaultID ) { return new StorageError ( 409 , "ContainerAlreadyExists" , "The specified container already exists." , contextID ) ; } public static getBlobAlreadyExists ( contextID = DefaultID ) { return new StorageError ( 409 , "BlobAlreadyExists" , "The specified blob already exists." , contextID ) ; } public static getBlobNotFound ( contextID = DefaultID ) { return new StorageError ( 404 , "BlobNotFound" , "The specified blob does not exist." , contextID ) ; } public static getInvalidQueryParameterValue ( contextID = DefaultID , parameterName ? , parameterValue ? , reason ? ) { const additionalMessages = { } ; if ( parameterName ) { additionalMessages . QueryParameterName = parameterName ; } if ( parameterValue ) { additionalMessages . QueryParameterValue = parameterValue ; } if ( reason ) { additionalMessages . Reason = reason ; } return new StorageError ( 400 , "InvalidQueryParameterValue" , `Value for one of the query parameters specified in the request URI is invalid.` , contextID , additionalMessages ) ; } public static getOutOfRangeInput ( contextID = DefaultID , parameterName ? , parameterValue ? , reason ? ) { const additionalMessages = { } ; if ( parameterName ) { additionalMessages . QueryParameterName = parameterName ; } if ( parameterValue ) { additionalMessages . QueryParameterValue = parameterValue ; } if ( reason ) { additionalMessages . Reason = reason ; } return new StorageError ( 400 , "OutOfRangeInput" , `One of the request inputs is out of range.` , contextID , additionalMessages ) ; } public static getInvalidOperation ( contextID = DefaultID , message = "" ) { return new StorageError ( 400 , "InvalidOperation" , message , contextID ) ; } public static getInvalidBlockList ( contextID = DefaultID ) { return new StorageError ( 400 , "InvalidBlockList" , "The specified block list is invalid." , contextID ) ; } public static getInvalidAuthenticationInfo ( contextID = DefaultID ) { return new StorageError ( 400 , "InvalidAuthenticationInfo" , "Authentication information is not given in the correct format. Check the value of Authorization header." , contextID ) ; } public static getMd5Mismatch ( contextID = DefaultID , userSpecifiedMd5 , serverCalculatedMd5 ) { return new StorageError ( 400 , "Md5Mismatch" , "The MD5 value specified in the request did not match with the MD5 value calculated by the server." , contextID , { UserSpecifiedMd5 : userSpecifiedMd5 , ServerCalculatedMd5 : serverCalculatedMd5 } ) ; } public static getInvalidPageRange ( contextID ) { return new StorageError ( 416 , "Requested Range Not Satisfiable" , "The page range specified is invalid." , contextID ) ; } public static getInvalidLeaseDuration ( contextID = DefaultID ) { return new StorageError ( 400 , "InvalidHeaderValue" , "The value for one of the HTTP headers is not in the correct format." , contextID ) ; } public static getInvalidLeaseBreakPeriod ( contextID = DefaultID ) { return new StorageError ( 400 , "InvalidHeaderValue" , "The value for one of the HTTP headers is not in the correct format." , contextID ) ; } public static getInvalidId ( contextID ) { return new StorageError ( 400 , "InvalidHeaderValue" , "The value for one of the HTTP headers is not in the correct format." , contextID ) ; } public static getInvalidBlobOrBlock ( contextID = DefaultID ) { return new StorageError ( 400 , "InvalidBlobOrBlock" , "The specified blob or block content is invalid." , contextID ) ; } public static getLeaseAlreadyPresent ( contextID = DefaultID ) { return new StorageError ( 409 , "LeaseAlreadyPresent" , "There is already a lease present." , contextID ) ; } public static getLeaseIsBreakingAndCannotBeAcquired ( contextID = DefaultID ) { return new StorageError ( 409 , "LeaseIsBreakingAndCannotBeAcquired" , "There is already a breaking lease, and can't  be acquired." , contextID ) ; } public static getLeaseNotPresentWithLeaseOperation ( contextID = DefaultID ) { return new StorageError ( 409 , "LeaseNotPresentWithLeaseOperation" , "There is currently no lease on the container or blob." , contextID ) ; } public static getLeaseIdMismatchWithLeaseOperation ( contextID = DefaultID ) { return new StorageError ( 409 , "LeaseIdMismatchWithLeaseOperation" , "The lease ID specified did not match the lease ID for the container or blob." , contextID ) ; } public static getLeaseIsBrokenAndCannotBeRenewed ( contextID = DefaultID ) { return new StorageError ( 409 , "LeaseIsBrokenAndCannotBeRenewed" , "The lease ID matched, but the lease has been broken explicitly and cannot be renewed." , contextID ) ; } public static getLeaseIsBreakingAndCannotBeChanged ( contextID = DefaultID ) { return new StorageError ( 409 , "LeaseIsBreakingAndCannotBeChanged" , "The lease ID matched, but the lease is currently in breaking state and cannot be changed." , contextID ) ; } public static getContainerLeaseIdMissing ( contextID = DefaultID ) { return new StorageError ( 412 , "LeaseIdMissing" , "There is currently a lease on the container and no lease ID was specified in the request." , contextID ) ; } public static getContainerLeaseIdMismatchWithContainerOperation ( contextID = DefaultID ) { return new StorageError ( 412 , "LeaseIdMismatchWithContainerOperation" , "The lease ID specified did not match the lease ID for the container." , contextID ) ; } public static getContainerLeaseLost ( contextID = DefaultID ) { return new StorageError ( 412 , "LeaseNotPresentWithContainerOperation" , "A lease ID was specified, but the lease for the container has expired." , contextID ) ; } public static getBlobLeaseIdMismatchWithLeaseOperation ( contextID ) { return new StorageError ( 409 , "LeaseIdMismatchWithLeaseOperation" , "The lease ID specified did not match the lease ID for the blob." , contextID ) ; } public static getBlobLeaseNotPresentWithLeaseOperation ( contextID ) { return new StorageError ( 409 , "LeaseNotPresentWithLeaseOperation" , "There is currently no lease on the blob." , contextID ) ; } public static getBlobSnapshotsPresent ( contextID = DefaultID ) { return new StorageError ( 400 , "SnapshotsPresent" , "This operation is not permitted because the blob is snapshot." , contextID ) ; } public static getBlobLeaseIdMissing ( contextID = DefaultID ) { return new StorageError ( 412 , "LeaseIdMissing" , "There is currently a lease on the blob and no lease ID was specified in the request." , contextID ) ; } public static getBlobLeaseIdMismatchWithBlobOperation ( contextID = DefaultID ) { return new StorageError ( 412 , "LeaseIdMismatchWithBlobOperation" , "The lease ID specified did not match the lease ID for the blob." , contextID ) ; } public static getBlobLeaseLost ( contextID = DefaultID ) { return new StorageError ( 412 , "LeaseNotPresentWithBlobOperation" , "A lease ID was specified, but the lease for the blob has expired." , contextID ) ; } public static getAuthorizationFailure ( contextID ) { return new StorageError ( 403 , "AuthorizationFailure" , "Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature." , contextID ) ; } public static getAuthenticationFailed ( contextID = DefaultID , authenticationErrorDetail ) { return new StorageError ( 403 , "AuthenticationFailed" , "Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature." , contextID , { AuthenticationErrorDetail : authenticationErrorDetail } ) ; } public static getBlobInvalidBlobType ( contextID = DefaultID ) { return new StorageError ( 409 , "InvalidBlobType" , "The blob type is invalid for this operation." , contextID ) ; } public static getAccessTierNotSupportedForBlobType ( contextID ) { return new StorageError ( 400 , "AccessTierNotSupportedForBlobType" , "The access tier is not supported for this blob type." , contextID ) ; } public static getMultipleConditionHeadersNotSupported ( contextID ) { return new StorageError ( 400 , "MultipleConditionHeadersNotSupported" , "Multiple condition headers are not supported." , contextID ) ; } public static getBlobSnapshotsPresent_hassnapshot ( contextID ) { return new StorageError ( 409 , "SnapshotsPresent" , "This operation is not permitted because the blob has snapshots." , contextID ) ; } public static getBlobCannotChangeToLowerTier ( contextID ) { return new StorageError ( 409 , "CannotChangeToLowerTier" , "A higher blob tier has already been explicitly set." , contextID ) ; } public static getBlobBlobTierInadequateForContentLength ( contextID ) { return new StorageError ( 409 , "BlobTierInadequateForContentLength" , "Specified blob tier size limit cannot be less than content length." , contextID ) ; } public static getAuthorizationSourceIPMismatch ( contextID ) { return new StorageError ( 403 , "AuthorizationSourceIPMismatch" , "This request is not authorized to perform this operation using this source IP {SourceIP}." , contextID ) ; } public static getAuthorizationProtocolMismatch ( contextID ) { return new StorageError ( 403 , "AuthorizationProtocolMismatch" , "This request is not authorized to perform this operation using this protocol." , contextID ) ; } public static getAuthorizationPermissionMismatch ( contextID ) { return new StorageError ( 403 , "AuthorizationPermissionMismatch" , "This request is not authorized to perform this operation using this permission." , contextID ) ; } public static getAuthorizationServiceMismatch ( contextID ) { return new StorageError ( 403 , "AuthorizationServiceMismatch" , "This request is not authorized to perform this operation using this service." , contextID ) ; } public static getAuthorizationResourceTypeMismatch ( contextID ) { return new StorageError ( 403 , "AuthorizationResourceTypeMismatch" , "This request is not authorized to perform this operation using this resource type." , contextID ) ; } public static getFeatureVersionMismatch ( contextID ) { return new StorageError ( 409 , "FeatureVersionMismatch" , "Stored access policy contains a permission that is not supported by this version." , contextID ) ; } public static getCopyIdMismatch ( contextID ) { return new StorageError ( 409 , "CopyIdMismatch" , "The specified copy ID did not match the copy ID for the pending copy operation." , contextID ) ; } public static getNoPendingCopyOperation ( contextID ) { return new StorageError ( 409 , "NoPendingCopyOperation" , "There is currently no pending copy operation." , contextID ) ; } public static getSnapshotsPresent ( contextID ) { return new StorageError ( 409 , "SnapshotsPresent" , "This operation is not permitted while the blob has snapshots." , contextID ) ; } public static getConditionNotMet ( contextID ) { return new StorageError ( 412 , "ConditionNotMet" , "The condition specified using HTTP conditional header(s) is not met." , contextID ) ; } public static getMaxBlobSizeConditionNotMet ( contextID = DefaultID ) { return new StorageError ( 412 , "MaxBlobSizeConditionNotMet" , "The max blob size condition specified was not met." , contextID ) ; } public static getAppendPositionConditionNotMet ( contextID = DefaultID ) { return new StorageError ( 412 , "AppendPositionConditionNotMet" , "The append position condition specified was not met." , contextID ) ; } public static getSequenceNumberConditionNotMet ( contextID ) { return new StorageError ( 412 , "SequenceNumberConditionNotMet" , "The condition specified using HTTP conditional header(s) is not met." , contextID ) ; } public static getNotModified ( contextID ) { return new StorageError ( 304 , "ConditionNotMet" , "The condition specified using HTTP conditional header(s) is not met." , contextID ) ; } public static getUnsatisfiableCondition ( contextID ) { return new StorageError ( 400 , "UnsatisfiableCondition" , "The request includes an unsatisfiable condition for this operation." , contextID ) ; } public static getInvalidHeaderValue ( contextID = "" , additionalMessages ? ) { if ( additionalMessages === undefined ) { additionalMessages = { } ; } return new StorageError ( 400 , "InvalidHeaderValue" , "The value for one of the HTTP headers is not in the correct format." , contextID , additionalMessages ) ; } public static getBlobArchived ( contextID = "" , additionalMessages ? ) { if ( additionalMessages === undefined ) { additionalMessages = { } ; } return new StorageError ( 409 , "BlobArchived" , "This operation is not permitted on an archived blob." , contextID , additionalMessages ) ; } public static getInvalidCorsHeaderValue ( contextID = "" , additionalMessages ? ) { return new StorageError ( 400 , "InvalidHeaderValue" , "A required CORS header is not present." , contextID , additionalMessages ) ; } public static corsPreflightFailure ( contextID = "" , additionalMessages ? ) { return new StorageError ( 403 , "CorsPreflightFailure" , "CORS not enabled or no matching rule found for this request." , contextID , additionalMessages ) ; } public static getCannotVerifyCopySource ( contextID , statusCode , message , additionalMessages ? ) { return new StorageError ( statusCode , "CannotVerifyCopySource" , message , contextID , additionalMessages ) ; } public static getInvalidResourceName ( contextID = "" ) { return new StorageError ( 400 , "InvalidResourceName" , `The specifed resource name contains invalid characters.` , contextID ) ; } public static getOutOfRangeName ( contextID = "" ) { return new StorageError ( 400 , "OutOfRangeInput" , `The specified resource name length is not within the permissible limits.` , contextID ) ; } public static getUnexpectedSyncCopyStatus ( contextID , copyStatus ) { return new StorageError ( 409 , "UnexpectedSyncCopyStatus" , 'Expected copyStatus to be "success" but got different status.' , contextID , { ReceivedCopyStatus : copyStatus } ) ; } }