-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from FoxMalder-coder/module9-task1
- Loading branch information
Showing
39 changed files
with
388 additions
and
109 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const STATIC_UPLOAD_ROUTE = '/upload'; | ||
export const STATIC_FILES_ROUTE = '/static'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
src/shared/libs/rest/exception-filter/app-exception-filter.ts
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
src/shared/libs/rest/exception-filter/app.exception-filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { injectable, inject } from 'inversify'; | ||
import { Component } from '../../../const.js'; | ||
import { createErrorObject } from '../../../helpers/common.js'; | ||
import { ApplicationError } from '../types/application-error.enum.js'; | ||
import { ExceptionFilter } from './exception-filter.interface.js'; | ||
import { Logger } from '../../logger/logger.interface.js'; | ||
|
||
@injectable() | ||
export class AppExceptionFilter implements ExceptionFilter { | ||
constructor( | ||
@inject(Component.Logger) private readonly logger: Logger | ||
) { | ||
this.logger.info('Register AppExceptionFilter'); | ||
} | ||
|
||
public catch(error: Error, _req: Request, res: Response, _next: NextFunction): void { | ||
this.logger.error(error.message, error); | ||
res | ||
.status(StatusCodes.INTERNAL_SERVER_ERROR) | ||
.json(createErrorObject(ApplicationError.ServiceError, error.message)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/shared/libs/rest/exception-filter/http-error.exception-filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { injectable, inject } from 'inversify'; | ||
import { Component } from '../../../const.js'; | ||
import { createErrorObject } from '../../../helpers/common.js'; | ||
import { Logger } from '../../logger/logger.interface.js'; | ||
import { HttpError } from '../http-error.js'; | ||
import { ApplicationError } from '../types/application-error.enum.js'; | ||
import { ExceptionFilter } from './exception-filter.interface.js'; | ||
|
||
@injectable() | ||
export class HttpErrorExceptionFilter implements ExceptionFilter { | ||
constructor( | ||
@inject(Component.Logger) private readonly logger: Logger | ||
) { | ||
this.logger.info('Register HttpErrorExceptionFilter'); | ||
} | ||
|
||
public catch(error: unknown, req: Request, res: Response, next: NextFunction): void { | ||
if (!(error instanceof HttpError)) { | ||
return next(error); | ||
} | ||
|
||
this.logger.error(`[HttpErrorException]: ${req.path} # ${error.message}`, error); | ||
|
||
res | ||
.status(StatusCodes.BAD_REQUEST) | ||
.json(createErrorObject(ApplicationError.CommonError, error.message)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/shared/libs/rest/exception-filter/validation.exception-filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { injectable, inject } from 'inversify'; | ||
import { Component } from '../../../const.js'; | ||
import { createErrorObject } from '../../../helpers/common.js'; | ||
import { ApplicationError } from '../types/application-error.enum.js'; | ||
import { ExceptionFilter } from './exception-filter.interface.js'; | ||
import { Logger } from '../../logger/logger.interface.js'; | ||
import { ValidationError } from '../validation-error.js'; | ||
|
||
@injectable() | ||
export class ValidationExceptionFilter implements ExceptionFilter { | ||
constructor( | ||
@inject(Component.Logger) private readonly logger: Logger | ||
) { | ||
this.logger.info('Register ValidationExceptionFilter'); | ||
} | ||
|
||
public catch(error: unknown, _req: Request, res: Response, next: NextFunction): void { | ||
if (!(error instanceof ValidationError)) { | ||
return next(error); | ||
} | ||
|
||
this.logger.error(`[ValidationException]: ${error.message}`, error); | ||
|
||
error.details.forEach( | ||
(errorField) => this.logger.warn(`[${errorField.property}] — ${errorField.messages}`) | ||
); | ||
|
||
res | ||
.status(StatusCodes.BAD_REQUEST) | ||
.json(createErrorObject(ApplicationError.ValidationError, error.message, error.details)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.