import { FULL_METADATA_ACCEPT , MINIMAL_METADATA_ACCEPT , NO_METADATA_ACCEPT , TABLE_API_VERSION } from "../../table/utils/constants" ; import Context from "../generated/Context" ; import MiddlewareError from "../generated/errors/MiddlewareError" ; import { jsonToXML } from "../generated/utils/xml" ; import { getPayloadFormat } from "../utils/utils" ; export class extends MiddlewareError export default class StorageError extends MiddlewareError { public readonly storageErrorCode : string ; public readonly storageErrorMessage : string ; public readonly storageRequestID : string ; param { number } statusCode param { string } storageErrorCode param { string } storageErrorMessage param { string } storageRequestID param { { [ key : string ] : string } } storageAdditionalErrorMessages param Context memberof constructor ( statusCode , storageErrorCode , storageErrorMessage , storageRequestID , storageAdditionalErrorMessages = { } , context ) { const pyaload = getPayloadFormat ( context ) ; const isJSON = pyaload === NO_METADATA_ACCEPT || pyaload === MINIMAL_METADATA_ACCEPT || pyaload === FULL_METADATA_ACCEPT ; const bodyInJSON = isJSON ? { code : storageErrorCode , message : { lang : "en-US" , value : `${ storageErrorMessage }\nRequestId:${ storageRequestID }\nTime:${ new Date ( ) . toISOString ( ) }` } } : { Code : storageErrorCode , Message : `${ storageErrorMessage }\nRequestId:${ storageRequestID }\nTime:${ new Date ( ) . toISOString ( ) }` } ; for ( const key in storageAdditionalErrorMessages ) { if ( storageAdditionalErrorMessages . hasOwnProperty ( key ) ) { const element = storageAdditionalErrorMessages [ key ] ; bodyInJSON [ key ] = element ; } } const body = isJSON ? JSON . stringify ( { "odata.error" : bodyInJSON } ) : jsonToXML ( { Error : bodyInJSON } ) ; super ( statusCode , storageErrorMessage , undefined , { "x-ms-error-code" : storageErrorCode , "x-ms-request-id" : storageRequestID , "x-ms-version" : TABLE_API_VERSION } , body , isJSON ? `${ pyaload };streaming=true;charset=utf-8` : "application/xml" ) ; this . name = "StorageError" ; this . storageErrorCode = storageErrorCode ; this . storageErrorMessage = storageErrorMessage ; this . storageRequestID = storageRequestID ; } }