question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Express middleware `express-error-slack` doesn't work with NestJS, but works for express server

See original GitHub issue

Bug Report

Current behavior

NestJS documentation explains that nest Middleware is the same as express middleware. However, when trying to use the express-error-slack middleware, it seems the function never gets called. This doesn’t seem to be a problem with the package itself, since the same package works as expected in express

https://github.com/chunkai1312/express-error-slack

Input Code

main.ts:


import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import * as helmet from 'helmet';
import * as expressslack from 'express-error-slack';

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.useGlobalPipes(new ValidationPipe());
    app.use(expressslack({ webhookUri: 'webhookURL' }));
    app.use(helmet());
    await app.listen(3000);
}
bootstrap();

Controller


@Controller()
export class MyController {
    @Get('error')
    async error() {
        throw new Error('Error!');
    }
}

I would expect the express slack middleware to pick up the error and handle it, but it’s not

Environment

Nest version: 6

For Tooling issues:

  • Node version: 10.15.1
  • Platform: Windows 10

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blitzmanncommented, Sep 17, 2019

@kamilmysliwiec I did not! Well I feel silly now. I will take ma look and verify this is what we’re looking for.

I also found a way to potentially do it with interceptors, was about to edit my response above with that information.

I still feel like the documentation should explicitly mention the issues with express error handling middleware. I assume there’s quite a few packages out there that wouldn’t work because of that. Unless I missed that in the documentation as well >.<

0reactions
kamilmysliwieccommented, Sep 30, 2019

It’s actually a duplicate of this https://github.com/nestjs/docs.nestjs.com/issues/215

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run express api server and socket alongside nest js?
I want to Implement a new module in nest js and run express, ... run express and nest on the same server but...
Read more >
Nest.js Brings TypeScript to Node.js and Express - Auth0
Let's learn about Nest.js, the new framework that takes advantage of TypeScript to create reliable and well structured Express applications.
Read more >
Interceptors | NestJS - A progressive Node.js framework
These details can be helpful in building more generic interceptors that can work across a broad set of controllers, methods, and execution contexts....
Read more >
@nestjs/common - npm
A progressive Node.js framework for building efficient and scalable server-side applications. NPM Version Package License NPM Downloads ...
Read more >
Getting started with continuous integration for Nest.js APIs
Developer A sits at a desk working on a beginning-level project. ... Nest.js is compatible with the majority of Express.js middleware.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found