Skip to content

Added functionality to modify event#15

Open
HenrikEngen wants to merge 2 commits into
masterfrom
feature/modifyEvent
Open

Added functionality to modify event#15
HenrikEngen wants to merge 2 commits into
masterfrom
feature/modifyEvent

Conversation

@HenrikEngen

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/events/index.ts Outdated
})})

if (response.status === 403) {
throw new ApiPatchError("You do not have access to edit event information.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an incorrect error. 403 doesnt have to mean "you do not have access". it could mean the token is not working. etc. Better respond with something more generic

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, is this better?

You do not have access to edit event information. If you believe you are supposed to have access to this, try logging out and back in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. "Access was denied. If you believe you are supposed to have access to this, try logging out and back in." is a lot better. Say what actually happened, not why you believe what happened happened. It makes troubleshooting harder

Comment thread src/events/index.ts
throw new ApiPatchError("You do not have access to edit event information.")
}
else if (!response.ok) {
throw new ApiPatchError((await response.json())['error']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, we should prioritize reading the error over simply reacting to 403. Always prefer the error messsage from the server if it exists, as it will be more descriptive.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay? In this scenario, if I prioritize !response.ok over response.status === 403, I get this:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

image image

Are you sure?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it is better to then try/catch the json decode, than to hardcode the 403 response, imo.

But even better, the server should probably always return a json response. lets do that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix something

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed something!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants