Skip to content
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: add opts to requireUserSession for error message and status code customization #76

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

dethdkn
Copy link
Contributor

@dethdkn dethdkn commented Apr 7, 2024

Hello, This PR introduces the ability to customize the status code and error message in the requireUserSession method. This feature is particularly useful for applications that are not in English.

I use the returned error message on my apps, and I wish I could translate the Unauthorized message to my language

@atinux
Copy link
Owner

atinux commented Apr 8, 2024

Thank you for the PR @dethdkn

Don't you want to translate on the application side instead of the API @dethdkn ?

@dethdkn
Copy link
Contributor Author

dethdkn commented Apr 8, 2024

Hey @atinux I translate both 😅, Most of my $fetch are like this

const res = await $fetch('/do-something', { method: 'post', body: body.data })
	.catch((err) => { toast.add({ title: err.data.message, icon: 'i-heroicons-exclamation-triangle', color: 'red' }) })

I get the returned api message and show it as a toast
I'm not sure if it's the best way to work with $fetch catch, but, it has been working here since my api have multiple throws.

@dethdkn
Copy link
Contributor Author

dethdkn commented Apr 8, 2024

Also sorry for the inconsistent spacing on the opts type, I thought eslint would fix that

@atinux
Copy link
Owner

atinux commented Apr 15, 2024

Happy to fix the conflicts with the new eslint rules? see #79

@dethdkn
Copy link
Contributor Author

dethdkn commented Apr 15, 2024

Fixed @atinux 🫡

@atinux atinux merged commit 015e847 into atinux:main Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants