import RESTController from "../RESTController" ; import RESTRequest from "../request" ; import { BloxyHttpError } from "../../../util/errors/errors" ; import { RESTResponseDataType } from "../../../interfaces/RESTInterfaces" ; export default class RESTResponse { public controller : RESTController ; public request : RESTRequest ; public responseData : RESTResponseDataType ; constructor ( controller , request , responseData ) { this . controller = controller ; this . request = request ; this . responseData = responseData ; } async process ( ) { const allProcessed = this . controller . responseHandlers . map ( handler => handler ( this ) ) ; if ( allProcessed . every ( processed => processed === true ) ) { return this . responseData ; } else { const error = allProcessed . find ( error => error instanceof BloxyHttpError && error . name === "BloxyInvalidStatusMessageError" && error . statusMessage . includes ( "Token Validation Failed" ) ) ; if ( error ) { if ( this . request . attempts - 1 === this . controller . getXCSRFTokenRefreshMaxRetries ( ) ) { throw error ; } else { this . controller . options . xcsrf = undefined ; return this . request . send ( ) ; } } throw allProcessed . find ( error => error instanceof Error ) ; } } }