-
Hello, If I try something like the following: import { mutate } from 'swr';
…
try {
const foo = await mutate('bar', async () => {
throw new Error('an error occurred');
});
console.log({ foo }); // { foo: undefined }
} catch (e) {
// this is never executed
console.error(e);
} Mutate swallows the error and it's never heard from. However, the docs seem to state that I should be able to catch this. Here's what the docs say: try {
const user = await mutate('/api/user', updateUser(newUser))
} catch (error) {
// Handle an error while updating the user here
} That is here: https://github.com/vercel/swr#returned-data-from-mutate. What's going on? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Is it supposed to be that I would do: try {
await mutate('bar', await (async () => {
throw new Error('an error occurred');
})());
} catch (e) {
console.error(e);
} so that the function is run and evaluated and it's results are passed to mutate? |
Beta Was this translation helpful? Give feedback.
-
@zjr I've tried to run your code snippet in codesandbox, and I did recieved the error in the console. see the trace below did you try the latest version of swr (0.2.3 by the date I reply this thread)? |
Beta Was this translation helpful? Give feedback.
@zjr I've tried to run your code snippet in codesandbox, and I did recieved the error in the console. see the trace below
did you try the latest version of swr (0.2.3 by the date I reply this thread)?