I want to create an errorHandler middleware for my app. I used KoaJs for my web application and my error basic handler function like that:
error-handler.ts:
import { Context } from "koa";
export const errorHandler : any = (err : Error, ctx : Context ) =>{
console.log("Something went wrong") ====>>> Its Work
ctx.status = 403. ========>>>> Not work
ctx.body = "asdasd" =========>>>> Not work
}
And my endpoint which used error handler like that:
public static async helloWorld(ctx: BaseContext): Promise<void> {
throw new Error ('Error Here');
}
And my app.js like that:
import Koa from "koa";
import { errorHandler } from './middleware/error-handler';
...
app.use(errorHandler)
...
And When I send request to endpoint I getting an error like that :
Why Im getting this error? How can I solve this problem?