-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: normalize errors #243
Comments
Hello, still me here :). I updated to latest version of the module to try evolutions and so on ("^0.0.10"). Default user profile request works like a charm, thanks a lot for this! I have questions/concerns about errors management so it might be the right place here. Concerning errors management for the login method: I see that the useDirectusAuth().login method catch all errors, print them in the console and return a null value:
I don't know if/how you have planned to change this but I think errors causes/details have to be thrown in one way or another, because we need to know for example that the password is wrong, based on returned payload or that the server is down or whatever kind of error has happened to warn the user about it and/or handle the issue. This behaviour seems to be also found in other methods like useDirectusItems().createItem where I can also only 'blindly' throw a message and not analyse and handle it properly based on returned response if any. Why not just throwing the raw error instead of replying with null for the moment in all final catch methods? Is the h3's createError evolution planned to take care of all this? |
Exactly, but since I wanted to investigate a little bit more how errors are generated in the SDK I decided to postpone it to the next minor release after the stable 6.0.x was made |
I just found a very very annoying use case due to the fact of not throwing errors: I have exactly the same behavior, that it work or not, as the return value is undefined either if it works or not... I am not able to handle, even blindly the deletion error. |
And the same might happen for "dark hole" items, where you only have creation permissions and no read permission, as Directus will reply with a 204 without any body. |
there are a number of functions from the SDK, in particular the On the other hand, while working on I've already did commit some changes on this topic, but I'll need to finish some other few before releasing a new Side effectThe SDK has a few errors that are not currently properly handled, blocking UX. |
@zguig52 I've updated Now we should be able to handle all the errors caused during a fetch, with the only handful of generic errors generated by the SDK for things like missing Based on the ETA and direction of the Directus issue I'll either close this for now or leave it open, but feel free to write if you encounter any error that could be caused by me (in that case remember to provide a reproduction). |
That's fantastic, thanks a lot for this! Included in a try catch:
Usage:
With async syntax (const { data, error}):
Usage:
One remark, when using the readItems, query parameter signature are a bit different from the readAsyncItems: BTW, thanks for the example on how to type the different parameters of functions in your release notes, it helped me a lot to remove many //@ts-ignore :)! |
Thanks for testing things out! Much appreciated 🔥
Are you referring to the fact that ... readItems('posts', { fields: ['*'] })
// compared to
... readAsyncItems('posts', { query: { fields: ['*'] } }) If yes then this is intentional for a number of reasons:
Yeah, once all the implementations and bugs are settled I would like to start filling the new docs with tons of examples. It's way easier to see how to use the tool instead of reading how it should be used. Currently there are still some places where BTW: this update also let you use defaults of any if no schema is passed to the main composables, meaning that things like <script setup lang="ts"> // using ts
const { readAsyncItems } = useDirectusItems() // no schema type passed
const fields = ref(['id', 'title']) // normal `string[]` type
const { data } = await readAsyncItems('posts', {
query: {
fields // accepts the `Ref<scring[]>` type
},
watch: [fields]
})
</script> |
Thanks for the clarifications! |
createError
I've yet to test this, but instead of doing a bunch of
console.error
s I could serialize any error coming from Directus.Will update once I have time to work on this
The text was updated successfully, but these errors were encountered: