Skip to content
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

fix(root): better error handling and variables #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import bakeRouter from "./routes/bake";
import magicRouter from "./routes/magic";
import healthRouter from "./routes/health.js";


const isProduction = process.env.NODE_ENV === "production";

const app = express();
app.disable("x-powered-by");

app.use(cors({
origin: "*"
}));

if (process.env.NODE_ENV === "production") {
if (isProduction) {
app.use(pino({
level: "warn"
}));
Expand Down
10 changes: 3 additions & 7 deletions routes/bake.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import { bake, Dish } from "cyberchef/src/node/index.mjs";
*/
router.post("/", async function bakePost(req, res, next) {
try {
if (!req.body.input) {
throw new TypeError("'input' property is required in request body");
const noRecipeOrInput = !req.body.input || !req.body.recipe;
if(noRecipeOrInput) {
throw new TypeError(`'${!req.body.input ? 'input' : 'recipe'}' property is required in request body`);
}

if (!req.body.recipe) {
throw new TypeError("'recipe' property is required in request body");
}

const dish = await bake(req.body.input, req.body.recipe);

// Attempt to translate to another type. Any translation errors
Expand Down