-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(workers): optimize worker responses
- Loading branch information
1 parent
51a8dd3
commit 832dc76
Showing
3 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ yarn-error.log | |
# IDEs and editors | ||
/.idea | ||
.envrc | ||
.dev.vars | ||
.project | ||
.classpath | ||
.c9/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
|
||
export class CreatedResponse extends Response { | ||
/** | ||
* Created Response - HTTP 201 | ||
*/ | ||
public constructor(public readonly message: string) { | ||
super(JSON.stringify({ message }), { status: 201 }) | ||
|
||
this.headers.set('Content-Type', 'application/json') | ||
} | ||
} | ||
|
||
export class BadRequestResponse<R = string> extends Response { | ||
/** | ||
* Bad Request Response - HTTP 400 | ||
*/ | ||
public constructor(public readonly message: string, public readonly reason?: R) { | ||
super(JSON.stringify({ message, reason }), { status: 400 }) | ||
|
||
this.headers.set('Content-Type', 'application/json') | ||
} | ||
} | ||
|
||
export class InternalServerErrorResponse<R = Error> extends Response { | ||
/** | ||
* Internal Server Error Response - HTTP 500 | ||
*/ | ||
public constructor(public readonly message: string, public readonly reason?: R) { | ||
super(JSON.stringify({ message, reason }), { status: 500 }) | ||
|
||
this.headers.set('Content-Type', 'application/json') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters