Skip to content

Conversation

Diluka
Copy link
Contributor

@Diluka Diluka commented Jun 8, 2017

Let @Authorized() raising 401 and @Authorized("some_role") raising 403.


} else {
next();
}
});
} else {
if (!checkResult) {
this.handleError(new AccessDeniedError(action), actionMetadata, action);
this.handleError((actionMetadata.authorizedRoles.length === 0
Copy link
Contributor

Choose a reason for hiding this comment

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

all these code blocks become messy... maybe we should avoid using ternary if and beatify code?

Copy link
Contributor

Choose a reason for hiding this comment

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

ternary is faster, so if the libs want's to be fast, this should stay with other tail call optimizations 😜

Copy link
Member

Choose a reason for hiding this comment

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

so if the libs want's to be fast

I see you need time to heal from the traumatic experience of that conversation 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

The only traumatic thing is the hypocrisy:

  • Promise.resolve removes half on duplicated code block but it's slower, so we stick with messy code because "its important to make it performant as we can"
  • now "all these code blocks become messy", so we should remove ternary and tail call optimization to "beatify code"

So please be consistent - peformance at any cost or readable and maintainable code 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

@19majkel94 you should investigate a bit how Promise.resolve actually works, its not as simple as let vs const. We make decisions based on pros and cons of everything, its impossible to be consistent in everything, so make judging based on each scenario individually.

} else {
if (!checkResult) {
this.handleError(new AccessDeniedError(action), actionMetadata, action);
const handleError = (result: any) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, do you like this one?

this.handleError(new AccessDeniedError(action), actionMetadata, action);
const handleError = (result: any) => {
if (!result) {
return this.handleError((
Copy link
Contributor

Choose a reason for hiding this comment

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

multiline params this way do not look good, simplify this. extract error class in a separate variable if needed

@pleerock
Copy link
Contributor

everyone thinks its good to merge (not only performance and code style considerations 😆 ) ?

@pleerock pleerock merged commit e18178a into typestack:master Jun 13, 2017
@Diluka Diluka deleted the fix/auth-decorator-status-code branch June 14, 2017 02:10
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants