error TS2769 while trying to define strong-error-handler(using loopback framework in NodeJS)

Viewed 56

I am totally new to NodeJS(using Loopback framework) and need some help implementing error handlers.

I tried defining strong-error-handler as given in loopback documentation like:

app.bind(RestBindings.ERROR_WRITER_OPTIONS).to({debug: true});

And got the below error:

error TS2769: No overload matches this call.
  Overload 1 of 2, '(keyWithPath: BindingAddress<unknown>, session?: ResolutionSession | undefined): Promise<unknown>', gave the following error.
    Argument of type '(req: any, res: any) => any' is not assignable to parameter of type 'ResolutionSession'.
      Type '(req: any, res: any) => any' is missing the following properties from type 'ResolutionSession': stack, pushInjection, popInjection, currentInjection, and 8 more.
  Overload 2 of 2, '(keyWithPath: BindingAddress<unknown>, options: ResolutionOptions): Promise<unknown>', gave the following error.
    Value of type '(req: any, res: any) => any' has no properties in common with type 'ResolutionOptions'. Did you mean to call it?

Can someone please help me in resolving this?

Also an example to illustrate globalized error handling in nodejs using loopback would be of great help.

1 Answers

Hello from the LoopBack team

The error message does not seem to be relevant to your app.bind() code. The bind API is defined as follows:

class Context {
  bind<ValueType = BoundValue>(
    key: BindingAddress<ValueType>,
  );
}

The error message is mentioning keyWithPath and sessions/options arguments, which matches the API of Context.get API.

Can you please double-check that you posted the same source-code line where the compiler reported the error?

Also an example to illustrate globalized error handling in nodejs using loopback would be of great help.

What do you mean by globalized error handling? Are you trying to return localized (translated) error messages in your HTTP responses? I am not sure how easy is that to implement in LoopBack, can you please open a new GitHub issue for this feature request?

Related