You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The unhandler error captures should pass through the error middleware and should send the proper error message. All route should behave same using by passing error to error middleware
Current Behavior
For any first container config that is imported and its last router is giving this error:
Error: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:648:11)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at processImmediate (node:internal/timers:447:9)
Possible Solution
NA
Steps to Reproduce (for bugs)
controller.ts
import { Request, Response, NextFunction } from 'express';
import { injectable } from 'inversify';
import { BaseController } from '@sn/server';
import { AppError } from '@sn/core';
import { logDecorator } from '@sn/shared';
@injectable()
export class GetMetaController extends BaseController {
constructor() {
super();
}
@logDecorator()
public async executeImpl(
request: Request,
response: Response,
next: NextFunction
): Promise<any> {
try {
throw new Error('Throw some error');
// return this.ok<any>(response, { user: 1 });
} catch (err: any) {
return this.fail(response, new AppError.UnexpectedError(err), next);
}
}
}
import { AsyncContainerModule, interfaces } from 'inversify';
import { errorHandler } from '@core/error/ErrorHandler';
import TYPES from '@ioc/constant/Types';
import { RefVersionRouters } from './infrastructure/routers/RefVersionRouter';
import { GetRefVersionController } from './infrastructure/controller/GetRefVersionController';
import { GetMetaController } from './infrastructure/controller/GetMetaController';
const SystemConfigContainer = new AsyncContainerModule(
async (bind: interfaces.Bind) => {
try {
RefVersionRouters;
bind<GetRefVersionController>(TYPES.GetRefVersionController)
.to(GetRefVersionController)
.inRequestScope();
bind<GetMetaController>(TYPES.GetMetaController)
.to(GetMetaController)
.inRequestScope();
} catch (err: unknown) {
errorHandler.handleError('SystemIOC Error', err as Error);
}
}
);
export { SystemConfigContainer };
Ioc_config.ts
import { Container } from 'inversify';
import { errorHandler } from '@core/error/ErrorHandler';
import TYPES from './constant/Types';
import { SystemConfigContainer } from '@system-module/SystemIocConfig';
import { CheckConfigContainer } from '../module/check/CheckConfig';
import { UserConfigContainer } from '@user-module/UserIocConfig';
const InversifyConfigContainer = async () => {
const container = new Container();
try {
container.loadAsync(SystemConfigContainer);
container.loadAsync(UserConfigContainer);
container.loadAsync(CheckConfigContainer);
} catch (err: unknown) {
errorHandler.handleError('IOC Error', err as Error);
}
return container;
};
export { InversifyConfigContainer };
AppServer.ts
import 'reflect-metadata';
/* eslint-disable @typescript-eslint/no-explicit-any */
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('source-map-support').install();
import * as dotenv from 'dotenv';
import { InversifyExpressServer } from 'inversify-express-utils';
import { ExpressMiddleware, errorMiddleware } from './../middleware';
import { logger } from '@sn/shared';
// import { envConfig } from './config';
// import { ExitProcess } from './core/utils/ExitProcess';
dotenv.config();
const port = process.env.PORT || 3000;
export const appServer = async (config: any): Promise<void> => {
try {
const server = new InversifyExpressServer(config, null, {
rootPath: '/api/v1'
});
/* Adding middleware to express server */
server.setConfig((app) => {
new ExpressMiddleware(app);
});
server.setErrorConfig(errorMiddleware);
const serverInstance = server.build();
serverInstance.listen(port, () => {
logger.info(`Server running at http://127.0.0.1:${port}/`);
});
// ExitProcess(server);
} catch (err) {
logger.error('Error in SERVER', err);
}
};
MainAppServer.ts:
import 'module-alias/register';
import 'reflect-metadata';
import { InversifyConfigContainer } from '@ioc/IocConfig';
import sourceMapSupport from 'source-map-support';
import { logger } from '@sn/shared';
import { appServer } from '@sn/server';
sourceMapSupport.install();
const expressApp = (async (): Promise<void> => {
/* Setting up IoC */
try {
const containerConfig = await InversifyConfigContainer();
await appServer(containerConfig);
} catch (err) {
logger.error('Error', err);
}
})();
expressApp;
Context
If import is like this:
import { SystemConfigContainer } from '@system-module/SystemIocConfig';
import { CheckConfigContainer } from '../module/check/CheckConfig';
import { UserConfigContainer } from '@user-module/UserIocConfig';
Here the last route of import { SystemConfigContainer } from '@system-module/SystemIocConfig'; throws the error of request already sent
If we change the import like this
import { CheckConfigContainer } from '../module/check/CheckConfig';
import { SystemConfigContainer } from '@system-module/SystemIocConfig';
import { UserConfigContainer } from '@user-module/UserIocConfig';
Then last route of import { CheckConfigContainer } from '../module/check/CheckConfig'; throws the errror:
All other route works perfectly
Your Environment
"inversify": "^6.0.1",
"inversify-express-utils": "^6.4.3",
nodejs : 18+
MacOs
Stack trace
Current Behavior
For any first container config that is imported and its last router is giving this error:
Error: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:648:11)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at processImmediate (node:internal/timers:447:9)
The text was updated successfully, but these errors were encountered:
Expected Behavior
The unhandler error captures should pass through the error middleware and should send the proper error message. All route should behave same using by passing error to error middleware
Current Behavior
For any first container config that is imported and its last router is giving this error:
Possible Solution
NA
Steps to Reproduce (for bugs)
controller.ts
route.ts
module_config.ts
Ioc_config.ts
AppServer.ts
MainAppServer.ts:
Context
If import is like this:
Here the last route of import { SystemConfigContainer } from '@system-module/SystemIocConfig'; throws the error of request already sent
If we change the import like this
Then last route of import { CheckConfigContainer } from '../module/check/CheckConfig'; throws the errror:
All other route works perfectly
Your Environment
Stack trace
Current Behavior
The text was updated successfully, but these errors were encountered: