-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add status code decorator #438
Conversation
…t/add-status-code-decorator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I added some unrelated suggestions you can apply in other PR :)
): unknown { | ||
let body: object | string | number | boolean | undefined = undefined; | ||
let statusCode: HttpStatusCode | undefined = undefined; | ||
let httpStatusCode: HttpStatusCode | undefined = statusCode; | ||
|
||
if (value instanceof HttpResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad for not seeing this before, never use instanceof
on non native types, a user might end up with multiple versions of the core. Instead, consider an is
static method the same way AppError
does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if (statusCode !== undefined) { | ||
this._setStatus(request, response, statusCode); | ||
if (httpStatusCode !== undefined) { | ||
this._setStatus(request, response, httpStatusCode); | ||
} | ||
|
||
if (typeof body === 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should rely on the Accept header or delegate in the integration to decide whether or not string (text/plain mime type) or json (application/json mime) are used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That a good design question. We have 2 ways:
- Delegate to http drive
- Get agnostic response
Second option is the current implementation. idk what option is better, for me it's just a approach
@@ -2,8 +2,11 @@ export const METADATA_KEY: { | |||
controller: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rely on multiple constants instead of in a single object. Consider @inversifyjs/core
reflect keys as reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Added
Motivation
Continuing with industry standards, it’s interesting to have a decorator that allows changing the status code of the request without it being handled in the body of the function.