// If either of the required cookies are missing, but a state and code were provided via query string. we'll show an error to the user, and they will be asked to try the authorization flow again.
// If no record of this authorization could be found, but the user has a `state` and `vantaSourceId` cookie, throw an error.
thrownewError(`When a user tried to connect their Vanta account with their Fleet instance. No VantaConnection record with the sourceID ${this.req.signedCookies.vantaSourceId} could be found.`);
).intercept((error)=>{// If an error occurs while sending an authorization request, throw an error.
returnnewError(`When requesting an authorization token from Vanta for a Vanta connection with id ${recordOfThisAuthorization.id}, an error occurred. Full error: ${error}`);
});
// Update the VantaConnection record for this request with information from the authorization response from Vanta.
vantaAuthTokenExpiresAt:Date.now()+(vantaAuthorizationResponse.expires_in*1000),// The expires_in value in the response from Vanta is the number of seconds until the access_token expires, so we'll create a new JS timestamp set to that time.
thrownewError(`When trying to update a VantaConnection record (id: ${recordOfThisAuthorization.id}) with an authorization token from Vanta, the database record associated with this request has gone missing.`);