Getting UnhandledPromiseRejection in Solid Start server function that stops dev server
I have an
Here is the function:
Not sure exactly what's going on and hoping someone can perhaps provide insight.
asyncasync function in my Solid Start app and am receiving the following error message whenever it returns an ErrorError. UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<_Response>".
at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
at processPromiseRejections (node:internal/process/promises:475:17)
at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
code: 'ERR_UNHANDLED_REJECTION'
}UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<_Response>".
at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
at processPromiseRejections (node:internal/process/promises:475:17)
at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
code: 'ERR_UNHANDLED_REJECTION'
}Here is the function:
export async function loginOrRegister(formData: FormData) {
const username = String(formData.get("username"));
const password = String(formData.get("password"));
let error = validateUsername(username) || validatePassword(password);
if (error) {
// Promise.reject(new Error(error)). // <--- does not cause rejection, but UI does not show error message
return new Error(error); // <--- UI shows error message but dev server stops due to UnhandledPromiseRejection
}
try {
const user = await login(username, password);
const session = await getSession();
await session.update((d) => {
d.userId = user.id;
});
} catch (err) {
return err as Error;
}
throw redirect("/");
}export async function loginOrRegister(formData: FormData) {
const username = String(formData.get("username"));
const password = String(formData.get("password"));
let error = validateUsername(username) || validatePassword(password);
if (error) {
// Promise.reject(new Error(error)). // <--- does not cause rejection, but UI does not show error message
return new Error(error); // <--- UI shows error message but dev server stops due to UnhandledPromiseRejection
}
try {
const user = await login(username, password);
const session = await getSession();
await session.update((d) => {
d.userId = user.id;
});
} catch (err) {
return err as Error;
}
throw redirect("/");
}Not sure exactly what's going on and hoping someone can perhaps provide insight.
