3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 06:51:51 +00:00
zeppelin/backend/src/api/responses.ts

26 lines
629 B
TypeScript
Raw Normal View History

import { Response } from "express";
export function unauthorized(res: Response) {
res.status(403).json({ error: "Unauthorized" });
}
2019-06-23 19:18:41 +03:00
export function error(res: Response, message: string, statusCode: number = 500) {
res.status(statusCode).json({ error: message });
}
export function serverError(res: Response, message = "Server error") {
2019-06-23 19:18:41 +03:00
error(res, message, 500);
}
export function clientError(res: Response, message: string) {
2019-06-23 19:18:41 +03:00
error(res, message, 400);
}
export function notFound(res: Response) {
res.status(404).json({ error: "Not found" });
}
export function ok(res: Response) {
res.json({ result: "ok" });
}