Skip to content

Commit

Permalink
docs(tutorials/jokes): throw 403 instead of 401 if user is not the ow…
Browse files Browse the repository at this point in the history
…ner (#4688)
  • Loading branch information
chaukhoa97 authored Nov 25, 2022
1 parent 2248669 commit 080e5f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,4 @@
- zachdtaylor
- zainfathoni
- zhe
- chaukhoa97
10 changes: 5 additions & 5 deletions docs/tutorials/jokes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4631,7 +4631,7 @@ Awesome! We're ready to handle errors and it didn't complicate our happy path on

Oh, and don't you love how just like with the `ErrorBoundary`, it's all contextual? So the rest of the app continues to function just as well. Another point for user experience 💪

You know what, while we're adding catch boundaries. Why don't we improve the `app/routes/jokes/$jokeId.tsx` route a bit by allowing users to delete the joke if they own it. If they don't, we can give them a 401 error in the catch boundary.
You know what, while we're adding catch boundaries. Why don't we improve the `app/routes/jokes/$jokeId.tsx` route a bit by allowing users to delete the joke if they own it. If they don't, we can give them a 403 error in the catch boundary.

One thing to keep in mind with `delete` is that HTML forms only support `method="get"` and `method="post"`. They don't support `method="delete"`. So to make sure our form will work with and without JavaScript, it's a good idea to do something like this:

Expand Down Expand Up @@ -4708,7 +4708,7 @@ export const action: ActionFunction = async ({
throw new Response(
"Pssh, nice try. That's not your joke",
{
status: 401,
status: 403,
}
);
}
Expand Down Expand Up @@ -4756,7 +4756,7 @@ export function CatchBoundary() {
</div>
);
}
case 401: {
case 403: {
return (
<div className="error-container">
Sorry, but {params.jokeId} is not your joke.
Expand Down Expand Up @@ -4852,7 +4852,7 @@ export const action: ActionFunction = async ({
throw new Response(
"Pssh, nice try. That's not your joke",
{
status: 401,
status: 403,
}
);
}
Expand Down Expand Up @@ -4902,7 +4902,7 @@ export function CatchBoundary() {
</div>
);
}
case 401: {
case 403: {
return (
<div className="error-container">
Sorry, but {params.jokeId} is not your joke.
Expand Down

0 comments on commit 080e5f5

Please sign in to comment.