MohamedBeydoun / atlas

An express-typescript code generator
Apache License 2.0
6 stars 0 forks source link

Replace http code magic values with semantic variables #40

Closed AsFal closed 4 years ago

AsFal commented 4 years ago

Proposal

Current:

import { Request, Response } from "express";

const newController = {

    index: async (req: Request, res: Response) => {
        try {
            res.status(500).send({ msg: "Not Implemented" });
        } catch (err) {
            res.status(500).send(err);
        }
    },

}

export { newController };

Proposal


import { Request, Response } from "express";
import * as http from "http-status-codes";

const newController = {

    index: async (req: Request, res: Response) => {
        try {
            res.status(http.INTERNAL_SERVER_ERROR).send({ msg: "Not Implemented" });
        } catch (err) {
            res.status(http.INTERNAL_SERVER_ERROR).send(err);
        }
    },

}

export { newController };
## Notes
This would add the http-status-codes npm package as a dependency.
MohamedBeydoun commented 4 years ago

We can add our own status codes file in the util directory. This makes it so that users can edit/add to the status codes whenever they want to