Markus Johansson
10/15/2024, 3:01 PMawait this.validationContext.validate()
, then checking this.validationContext.isValid
My problem is that validationContext.validate()
will reject the promise if validation fails which outputs some more or less random "Uncaught (in promise) undefined" to the log and I can't seem to understand how to catch these. My call to validate()
is inside a try catch.
These errors only seem to happen when I'm navigating away from a step (hence while one of the sub-contexts are leaving being destroyed).
I'm I doing something fundamentally wrong here to validate the context?
https://cdn.discordapp.com/attachments/882984798719729704/1295763525272076368/ns-validation-rejection.gif?ex=670fd552&is=670e83d2&hm=7d9c9fbb64e1169ddf387a2c7c74a297ffbcbcebc013a731ae6230677e0c1a5f&Markus Johansson
10/15/2024, 3:12 PMvalidate()
without awaiting (for example during destroy).
@Niels Lyngsø Maybe you know if this is intentional?
https://cdn.discordapp.com/attachments/1295763525658087558/1295766222197231639/image.png?ex=670fd7d5&is=670e8655&hm=c6f4f6d5a5f3ca7a66ad3e26be954acf1c7e174342df6d48e7c749a60bf08e82&Niels Lyngsø
10/16/2024, 2:22 PM.then
That can be done in many ways but here is an example where we transform that promise into a promise that resolves in true/false depending on the outcome.
const resultsStatus = await validationContext.validate().then(
() => true,
() => false,
);
Regarding the intentional not awaiting method calls. That is on purpose — If you do not need to wait for the call to finish. Like if you dont do anything afterwards or waits for the result of it. Then there is no need to await it. 🙂Markus Johansson
10/16/2024, 3:32 PMtry {
await this.validation?.validate().catch((detail)=>{
console.log('catched ', detail);
});
} catch (error) {
console.log('error inside hasValidationError',error);
}
if(!this.validation.isValid){
// Do stuff
return;
}
// Do other stuff
return;
But as you're pointing out, using validate()
like that would mean that I don't have to check .isValid
after the call I guess.
I'll give it a try to see what happens 😄Niels Lyngsø
10/16/2024, 3:53 PMNiels Lyngsø
10/16/2024, 3:54 PMMarkus Johansson
10/17/2024, 10:51 PMthis.validate()
inside validation.controller.ts
that does not have any .then(..)
or catch(..)
, like I mentioned before they are just "fire and forget" - but if the promise is rejected - wouldn't that be a potential reason for the console errors that I'm seeing?
Really hard to understand where these rejections are coming from 🤔
https://cdn.discordapp.com/attachments/1295763525658087558/1296606426646577282/image.png?ex=6712e655&is=671194d5&hm=99beb8290b5c287e1160c1fafff2abcd546d614f0ec73d94bf21d352fcfbba36&Niels Lyngsø
10/18/2024, 7:28 AMNiels Lyngsø
10/18/2024, 11:09 AM