providing labels for status codes

This commit is contained in:
Mikayla Dobson
2022-12-13 09:46:45 -06:00
parent 5234e54bcc
commit 977f1d373a
4 changed files with 37 additions and 23 deletions

View File

@@ -1,11 +1,11 @@
import { CtlResponse } from "./types";
import { CtlResponse, StatusCode } from "./types";
export default class ControllerResponse<T> implements CtlResponse<T> {
ok: boolean
code: number
data: T | T[] | string
code: StatusCode
data: T | string
constructor(ok: boolean, code: number, data: T | T[] | string) {
constructor(ok: boolean, code: StatusCode, data: T | string) {
this.ok = ok
this.code = code
this.data = data

View File

@@ -1,5 +1,17 @@
export interface CtlResponse<T> {
ok: boolean
code: number
data: T | T[] | string
data: T | string
}
export enum StatusCode {
OK = 200,
NewContent = 201,
NoContent = 204,
NotModified = 304,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
ServerError = 500
}