I'm working on a NestJS backend that uses Firebase for authentication.
I want to catch all and only the exception from Firebase (for example when users use an expired token) and translate them to actual HTTP errors. I want the HttpExceptions
to be handled by the default filter.
I tried creating a new filter, but when I try to set the decorator like
@Catch(FirebaseError)
it doesn't compile saying 'FirebaseError' only refers to a type, but is being used as a value here.
I also tried leaving the @Catch()
without arguments and specifing the FirebaseError
type on in the catch
function, but it catches every exception.
// This code doesn't work
import { FirebaseError } from 'firebase';
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';
@Catch(FirebaseError)
export class FirebaseExceptionFilter implements ExceptionFilter<FirebaseError> {
catch(exception: FirebaseError, host: ArgumentsHost) {
// handle the exception
}
}
I want this filter to be called for FirebaseError
exceptions, but if I write @Catch(FirebaseError)
it doesn't compile, if I write @Catch()
it catches every exception.