Skip to content

suggestion: use a platform-agnostic filter via HTTP adapter abstraction #7

@micalevisk

Description

@micalevisk

hi! good lib!

as of now, due to the usage of response.type,response.send and so on, this exception filter only works for http adapters that implements such methods on their response object. Express and Fastify has them but 3rd-party http adapters might not have (because they aren't needed for nestjs core AFIAK)

response
.type(PROBLEM_CONTENT_TYPE)
.status(status)
.send({
...objectExtras,
type: [this.baseUri, type || this.getDefaultType(status)]
.filter(Boolean)
.join('/'),
title,
status,
detail,
});

My suggestion is using the HttpAdapterHost instead like the docs shows here: https://docs.nestjs.com/exception-filters#catch-everything

at same time, as we need to inject that dependency into the HttpExceptionFilter, there's no way to add this feature without introducing a breaking change because now one will need to supply that new parameter when using the app.useGlobalFilters bind approach (like described here)

so yeah, it's up to you 😄

btw I'd like to contribute to this project because of Hacktoberfest :p

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions