#UnhandledPromiseRejection: Causing whole app to be non-responsive

41 messages · Page 1 of 1 (latest)

celest tartan
#

Hello,

I have a purposely async function not being awaited, and, when it fails in the background the whole app becomes non-responsive, have to restart it to get it to start responding to API calls.

Can anyone help?

UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "An error happened!".
mighty pasture
#

You need to add a .catch if you don't plan to await it

celest tartan
#

dangerous dangerous!

#

THanks @mighty pasture -- wonder if there's a way to global catch all. also, ``` app.useGlobalInterceptors(new LoggerErrorInterceptor())


I'm using this from nestjs-pino and don't feel like it logs the errors in context properly since it combines it with the request that it errored on.
mighty pasture
#

You can use a process.on('unhandledRejection', errorhandler) but that's about it

celest tartan
#

I had that still caused problems.

#

I will try t he .catch

#

yeah, really weird..


backend-api-1  | [02:54:13.785] ERROR (122): Failed to callback transcription
backend-api-1  |     req: {
backend-api-1  |       "id": 3,
backend-api-1  |       "method": "POST",
backend-api-1  |       "url": "/deepgram/callback/5e16fc60-9dc8-4f96-b42b-05788533ced5",
backend-api-1  |       "query": {},
backend-api-1  |       "params": {
backend-api-1  |         "0": "deepgram/callback/5e16fc60-9dc8-4f96-b42b-05788533ced5"
backend-api-1  |       },
backend-api-1  |       "headers": {
backend-api-1  |         "content-type": "application/json",
backend-api-1  |         "user-agent": "PostmanRuntime/7.31.0",
backend-api-1  |         "accept": "*/*",
backend-api-1  |         "postman-token": "9fdea8ae-9ed5-4bb4-b294-0416a2ad2008",
backend-api-1  |         "host": "localhost:3001",
backend-api-1  |         "accept-encoding": "gzip, deflate, br",
backend-api-1  |         "connection": "keep-alive",
backend-api-1  |         "content-length": "1224009"
backend-api-1  |       },
backend-api-1  |       "remoteAddress": "::ffff:172.18.0.1",
backend-api-1  |       "remotePort": 59534
backend-api-1  |     }
backend-api-1  |     context: "DeepgramController"

is the response for this:

  this.deepgramService
      .callbackTranscription(params.fileUUID, req.body)
      .catch((error) => {
        this.logger.error('Failed to callback transcription', error)
      })

no error involved..

#

gonna look into my nest js pino implementation

mighty pasture
#

That's definitely not what I'd expect to see

celest tartan
#

I'm going crazy my man, this.logger.error('Failed to callback transcription', error, { error }) why doesn't this work lol

#

console.log works.

mighty pasture
#

I'd assume it's either an issue with pino or nest's logger interface

celest tartan
#

yeah when I remove app.use(pino)

#

it works

#

is this suppose to go anywhere special or any order? app.useGlobalInterceptors(new LoggerErrorInterceptor())?

mighty pasture
#

As long as it's before app listen

celest tartan
#

oh i found the issue

mighty pasture
#

What happened?

celest tartan
#

the context is the first param apparently?

#

this.logger.error(error, 'Failed to callback transcription') works

mighty pasture
#

Ah, probably a difference of what each parameter is for. Unlike console.log, each parameter means something

celest tartan
#

yeah, weird, because the interface doesn't match what it actually is saying, but, found an issue in the github.

#

anyway thanks @mighty pasture -- appreciate you.

mighty pasture
celest tartan
#

oh... you built ogma?

#

why don't you tell me to use that lol

mighty pasture
celest tartan
#

lmao all my requirements are is that I can do logger.error('msg', {context, error, etc})

#

and it will produce json logs in production.

#

I'll try @ogma/logger.

mighty pasture
#

Yeah, that would generally work

celest tartan
#

ahh it doesn't support the private readonly logger = new Logger(GptService.name) way to set a context?

mighty pasture
#

It should. You can either use new Logger() or you can use @OgmaLogger()

celest tartan
#

looking here to implement, don't see it use app.use(logger) anywhere

#

oh maybe it does it with the provider?

#

still kinda new to nest

mighty pasture
#

You should be able to get the ogma service via app.get(OgmaService) and pass that to app.setLogger() (or whatever nest's API is there. I forget at the moment

celest tartan
#

got it. ok

#

ty