* await-thenable * fix library watchers * moar eslint * fix test * fix typo * try to remove check void return * fix checksVoidReturn * move to domain utils * remove eslint ignores * chore: cleanup types * chore: use logger * fix: e2e --------- Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { ImmichLogger } from '@app/infra/logger';
|
|
import {
|
|
CallHandler,
|
|
ExecutionContext,
|
|
HttpException,
|
|
Injectable,
|
|
InternalServerErrorException,
|
|
NestInterceptor,
|
|
} from '@nestjs/common';
|
|
import { Observable, catchError, throwError } from 'rxjs';
|
|
import { isConnectionAborted } from '../../domain';
|
|
import { routeToErrorMessage } from '../app.utils';
|
|
|
|
@Injectable()
|
|
export class ErrorInterceptor implements NestInterceptor {
|
|
private logger = new ImmichLogger(ErrorInterceptor.name);
|
|
|
|
intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any> {
|
|
return next.handle().pipe(
|
|
catchError((error) =>
|
|
throwError(() => {
|
|
if (error instanceof HttpException === false) {
|
|
const errorMessage = routeToErrorMessage(context.getHandler().name);
|
|
if (!isConnectionAborted(error)) {
|
|
this.logger.error(errorMessage, error, error?.errors, error?.stack);
|
|
}
|
|
return new InternalServerErrorException(errorMessage);
|
|
} else {
|
|
return error;
|
|
}
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|