export class import Context from "../generated/Context" ; import StorageError from "./StorageError" ; const defaultID = "DefaultID" ; export default class StorageErrorFactory { public static getInvalidHeaderValue ( context , additionalMessages ? ) { if ( additionalMessages === undefined ) { additionalMessages = { } ; } return new StorageError ( 400 , "InvalidHeaderValue" , "The value for one of the HTTP headers is not in the correct format." , context . contextID || defaultID , additionalMessages , context ) ; } public static getInvalidInput ( context , additionalMessages ? ) { if ( additionalMessages === undefined ) { additionalMessages = { } ; } return new StorageError ( 400 , "InvalidInput" , "An error occurred while processing this request." , context . contextID || defaultID , additionalMessages , context ) ; } public static getTableAlreadyExists ( context ) { return new StorageError ( 409 , "TableAlreadyExists" , "The table specified already exists." , context . contextID || defaultID , undefined , context ) ; } public static getTableNameEmpty ( context ) { return new StorageError ( 400 , "TableNameEmpty" , "The specified table name is empty." , context . contextID || defaultID , undefined , context ) ; } public static getInvalidOperation ( context , message = "" ) { return new StorageError ( 400 , "InvalidOperation" , message , context . contextID || "" , undefined , context ) ; } public static getAuthorizationSourceIPMismatch ( context ) { return new StorageError ( 403 , "AuthorizationSourceIPMismatch" , "This request is not authorized to perform this operation using this source IP {SourceIP}." , context . contextID || defaultID , undefined , context ) ; } public static getAuthorizationProtocolMismatch ( context ) { return new StorageError ( 403 , "AuthorizationProtocolMismatch" , "This request is not authorized to perform this operation using this protocol." , context . contextID || defaultID , undefined , context ) ; } public static getAuthorizationPermissionMismatch ( context ) { return new StorageError ( 403 , "AuthorizationPermissionMismatch" , "This request is not authorized to perform this operation using this permission." , context . contextID || defaultID , undefined , context ) ; } public static getAuthorizationServiceMismatch ( context ) { return new StorageError ( 403 , "AuthorizationServiceMismatch" , "This request is not authorized to perform this operation using this service." , context . contextID || defaultID , undefined , context ) ; } public static getAuthorizationResourceTypeMismatch ( context ) { return new StorageError ( 403 , "AuthorizationResourceTypeMismatch" , "This request is not authorized to perform this operation using this resource type." , context . contextID || defaultID , undefined , context ) ; } public static getAccountNameEmpty ( context ) { return new StorageError ( 400 , "AccountNameEmpty" , "The specified account name is empty." , context . contextID || defaultID , undefined , context ) ; } public static getTableNotExist ( context ) { return new StorageError ( 404 , "TableNotFound" , "The table specified does not exist." , context . contextID || defaultID , undefined , context ) ; } public static getAuthorizationFailure ( context ) { 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." , context . contextID || defaultID , undefined , context ) ; } public static getEntityAlreadyExist ( context ) { return new StorageError ( 409 , "EntityAlreadyExists" , "The specified entity already exists." , context . contextID || defaultID , undefined , context ) ; } public static getPropertiesNeedValue ( context ) { return new StorageError ( 400 , "PropertiesNeedValue" , "The values are not specified for all properties in the entity." , context . contextID || defaultID , undefined , context ) ; } public static getAtomFormatNotSupported ( context ) { return new StorageError ( 415 , "AtomFormatNotSupported" , "Atom format is not supported." , context . contextID || defaultID , undefined , context ) ; } public static getPreconditionFailed ( context ) { return new StorageError ( 412 , "UpdateConditionNotSatisfied" , "The update condition specified in the request was not satisfied." , context . contextID || defaultID , undefined , context ) ; } public static getTableNotFound ( context ) { return new StorageError ( 404 , "TableNotFound" , "The table specified does not exist." , context . contextID || defaultID , undefined , context ) ; } public static ResourceNotFound ( context ) { return new StorageError ( 404 , "ResourceNotFound" , "The specified resource does not exist." , context . contextID || defaultID , undefined , context ) ; } public static getEntityNotFound ( context ) { return new StorageError ( 404 , "ResourceNotFound" , "The specified resource does not exist." , context . contextID || defaultID , undefined , context ) ; } public static getQueryConditionInvalid ( context ) { return new StorageError ( 400 , "InvalidInput" , "The query condition specified in the request is invalid." , context . contextID || defaultID , undefined , context ) ; } public static getInvalidResourceName ( context ) { return new StorageError ( 400 , "" , `The specifed resource name contains invalid characters.` , context . contextID || defaultID , undefined , context ) ; } public static getOutOfRangeName ( context ) { return new StorageError ( 400 , "" , `The specified resource name length is not within the permissible limits.` , context . contextID || defaultID , undefined , context ) ; } public static getInvalidXmlDocument ( context ) { return new StorageError ( 400 , "InvalidXmlDocument" , `XML specified is not syntactically valid.` , context . contextID || defaultID , undefined , context ) ; } public static getInvalidQueryParameterValue ( context , additionalMessages ? ) { if ( additionalMessages === undefined ) { additionalMessages = { } ; } return new StorageError ( 400 , "InvalidQueryParameterValue" , `Value for one of the query parameters specified in the request URI is invalid.` , context . contextID || defaultID , additionalMessages , context ) ; } public static getInvalidCorsHeaderValue ( context , additionalMessages ? ) { return new StorageError ( 400 , "InvalidHeaderValue" , "A required CORS header is not present." , context . contextID || defaultID , additionalMessages , context ) ; } public static corsPreflightFailure ( context , additionalMessages ? ) { return new StorageError ( 403 , "CorsPreflightFailure" , "CORS not enabled or no matching rule found for this request." , context . contextID || defaultID , additionalMessages , context ) ; } public static getInvalidAuthenticationInfo ( context ) { return new StorageError ( 400 , "InvalidAuthenticationInfo" , "Authentication information is not given in the correct format. Check the value of Authorization header." , context . contextID || defaultID , undefined , context ) ; } public static getAuthenticationFailed ( context , 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." , context . contextID || defaultID , { AuthenticationErrorDetail : authenticationErrorDetail } , context ) ; } }