Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question: inversify-express-utils] Error handling in action method #436

Open
lonix1 opened this issue Mar 5, 2019 · 0 comments
Open

[Question: inversify-express-utils] Error handling in action method #436

lonix1 opened this issue Mar 5, 2019 · 0 comments

Comments

@lonix1
Copy link

lonix1 commented Mar 5, 2019

None of the inversify-express-utils examples show the "correct" way to handle errors.

@httpGet("/:id")
  public async getUser(): Promise<User> {
    try {
      const id = this.httpContext.request.params.id;
      return await this._userRepository.get(id);
    }
    catch (e) {
      this.httpContext.response.status(404);
      // ...what goes here?                 <-------------------------------------
    }
  }

I know I can omit the return type, but I don't want to circumvent the type system.

So what do I put in the catch block?

Is it appropriate to use return Promise.reject(); or will that lead to problems?

@notaphplover notaphplover transferred this issue from inversify/InversifyJS Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant