![](/img/trans.png)
[英]NestJs - Catching MongoDB errors with a custom filter and @Catch(MongoError)
[英]How to @Catch() an interface in a NestJS filter
我正在研究使用Firebase進行身份驗證的NestJS后端。 我想捕獲Firebase的所有異常信息(例如,當用戶使用過期的令牌時),並將其轉換為實際的HTTP錯誤。 我希望HttpExceptions
由默認過濾器處理。
我嘗試創建一個新的過濾器,但是當我嘗試設置@Catch(FirebaseError)
之類的裝飾器時,它並沒有編譯為'FirebaseError' only refers to a type, but is being used as a value here.
我還嘗試了不帶參數的@Catch()
並在catch
函數中指定FirebaseError
類型為開,但是它捕獲了每個異常。
// 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
}
}
我希望為FirebaseError
異常調用此過濾器,但是如果我編寫@Catch(FirebaseError)
則它不會編譯,如果我編寫@Catch()
它將捕獲每個異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.