summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-17 20:37:13 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-17 20:37:13 +0200
commit70d9aa669e48bcc225c8afa2790fe57151c99277 (patch)
treefb2ccfd601384a8c4bc77220bbd95db78f1f28d5
parent:bug: fix login route (diff)
downloadserver-70d9aa669e48bcc225c8afa2790fe57151c99277.tar.xz
:loud_sound: verbose error handler
-rw-r--r--api/src/Server.ts5
-rw-r--r--api/src/middlewares/ErrorHandler.ts6
-rw-r--r--bundle/package-lock.json5
-rw-r--r--bundle/src/stats.ts5
4 files changed, 12 insertions, 9 deletions
diff --git a/api/src/Server.ts b/api/src/Server.ts
index ef72df5f..40e7c1c2 100644
--- a/api/src/Server.ts
+++ b/api/src/Server.ts
@@ -5,7 +5,7 @@ import { Authentication, CORS } from "./middlewares/";
 import { Config, db, initEvent } from "@fosscord/util";
 import { ErrorHandler } from "./middlewares/ErrorHandler";
 import { BodyParser } from "./middlewares/BodyParser";
-import { Router, Request, Response } from "express";
+import { Router, Request, Response, NextFunction } from "express";
 import mongoose from "mongoose";
 import path from "path";
 import { initRateLimits } from "./middlewares/RateLimit";
@@ -69,7 +69,8 @@ export class FosscordServer extends Server {
 
 		this.routes = await this.registerRoutes(path.join(__dirname, "routes", "/"));
 
-		api.use("*", (req: Request, res: Response, next) => {
+		api.use("*", (error: any, req: Request, res: Response, next: NextFunction) => {
+			if (error) return next(error);
 			res.status(404).json({
 				message: "404: Not Found",
 				code: 0
diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts
index 04d56026..d080e498 100644
--- a/api/src/middlewares/ErrorHandler.ts
+++ b/api/src/middlewares/ErrorHandler.ts
@@ -3,6 +3,8 @@ import { HTTPError } from "lambert-server";
 import { FieldError } from "../util/instanceOf";
 
 export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {
+	if (!error) next();
+
 	try {
 		let code = 400;
 		let httpcode = code;
@@ -24,9 +26,11 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne
 
 		if (httpcode > 511) httpcode = 400;
 
+		console.error(`[Error] ${code} ${req.url} ${message}`, errors || error);
+
 		res.status(httpcode).json({ code: code, message, errors });
 	} catch (error) {
-		console.error(error);
+		console.error(`[Internal Server Error] 500`, error);
 		return res.status(500).json({ code: 500, message: "Internal Server Error" });
 	}
 }
diff --git a/bundle/package-lock.json b/bundle/package-lock.json
index 354487be..379b1c18 100644
--- a/bundle/package-lock.json
+++ b/bundle/package-lock.json
@@ -42,7 +42,6 @@
 		"../api": {
 			"name": "@fosscord/api",
 			"version": "1.0.0",
-			"hasInstallScript": true,
 			"license": "ISC",
 			"dependencies": {
 				"@fosscord/util": "file:../util",
@@ -99,7 +98,6 @@
 		"../cdn": {
 			"name": "@fosscord/cdn",
 			"version": "1.0.0",
-			"hasInstallScript": true,
 			"license": "ISC",
 			"dependencies": {
 				"@fosscord/util": "file:../util",
@@ -141,7 +139,6 @@
 		"../gateway": {
 			"name": "@fosscord/gateway",
 			"version": "1.0.0",
-			"hasInstallScript": true,
 			"license": "ISC",
 			"dependencies": {
 				"@fosscord/util": "file:../util",
@@ -172,7 +169,7 @@
 		},
 		"../util": {
 			"name": "@fosscord/util",
-			"version": "1.3.55",
+			"version": "1.0.0",
 			"hasInstallScript": true,
 			"license": "GPLV3",
 			"dependencies": {
diff --git a/bundle/src/stats.ts b/bundle/src/stats.ts
index 0a10a855..6413f347 100644
--- a/bundle/src/stats.ts
+++ b/bundle/src/stats.ts
@@ -9,14 +9,15 @@ export function initStats() {
 
 	setInterval(async () => {
 		const [cpuUsed, memory, network] = await Promise.all([osu.cpu.usage(), osu.mem.info(), osu.netstat.inOut()]);
+		var networkUsage = "";
 		if (typeof network === "object") {
-			console.log(`[Network]: in ${network.total.inputMb}mb | out ${network.total.outputMb}mb`);
+			networkUsage = `| [Network]: in ${network.total.inputMb}mb | out ${network.total.outputMb}mb`;
 		}
 
 		console.log(
 			`[CPU] ${cpuUsed.toFixed(2)}% | [Memory] ${Math.round(
 				process.memoryUsage().rss / 1024 / 1024
-			)}mb/${memory.totalMemMb.toFixed(0)}mb`
+			)}mb/${memory.totalMemMb.toFixed(0)}mb ${networkUsage}`
 		);
 	}, 1000 * 30);
 }