如何求解nestjs fastify错误typeerror:response.status(...)。json不是函数
typeerror:wendesp.status(...)。json不是函数 在httpexceptionfilter.catch(/home/muhammedali/documents/100haryt_v2/src/common/http/http/http-exception.filter.ts:23:29) 在exceptionshandler.invokecustomfilters(/home/muhammedali/documents/100haryt_v2/node_modules/@nestjs/core/core/exceptions/exceptions/exceptions/exceptions handler.js:33:26) 在exceptionshandler.next(/home/muhammedali/documents/100haryt_v2/node_modules/@nestjs/core/core/exceptions/exceptions/exceptions/exceptions handler.js:13:18)
TypeError: response.status(...).json is not a function
at HttpExceptionFilter.catch (/home/muhammedali/Documents/100haryt_v2/src/common/http/http-exception.filter.ts:23:29)
at ExceptionsHandler.invokeCustomFilters (/home/muhammedali/Documents/100haryt_v2/node_modules/@nestjs/core/exceptions/exceptions-handler.js:33:26)
at ExceptionsHandler.next (/home/muhammedali/Documents/100haryt_v2/node_modules/@nestjs/core/exceptions/exceptions-handler.js:13:18)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是使用上述代码。尝试如下改变
instead of using the above code. try to change like as below
对我来说,当使用
graphQl
需要不同的异常处理程序时,发生这种情况。我只想将消息发送wenders.status
在使用http
作为协议时。您可以将其添加到Nestjs的自定义过滤器处理程序(也可以在 https:///docs.nestjs)中进行解释。 com/exception-filters )可以为您解决这个问题。 他们只会捕获httpexception
,而这将通过不向@catch
提供类型来捕获所有异常,
尽管在该解释中 Nestjs的文件您会添加
app.useglobalfilters(new AllexceptionsFiler());
这应该照顾它,并让所有您的非HTTP错误通过而不会崩溃。
For me this happened when using
graphql
which needs a different exception handler. I only want the messages send withresponse.status
when usinghttp
as protocol. You can add a custom filter handler for this to NestJS (as also explained at https://docs.nestjs.com/exception-filters) which can solve this for you. Though in that explanation they only catch theHttpException
while this will catch all exceptions by not providing a type to@Catch
For example my AllExceptionsFilter.ts looks like this:
In the setup file for NestJS you would add
app.useGlobalFilters(new AllExceptionsFiler());
This should take care of it and let all your non-http errors through without crashing.