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

Loosen HttpExceptionOptions.cause type #11665

Closed
1 task done
namoscato opened this issue May 25, 2023 · 3 comments
Closed
1 task done

Loosen HttpExceptionOptions.cause type #11665

namoscato opened this issue May 25, 2023 · 3 comments
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@namoscato
Copy link
Contributor

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

The HttpExceptionOptions.cause type is strictly Error | undefined which requires client-side handling with TypeScript's useUnknownInCatchVariables flag (enabled by default in v4.4), i.e.

try {
  // ...
} catch (error) {
  throw new UnauthorizedException(undefined, {
    cause: error instanceof Error ? error : undefined,
  });
}

Describe the solution you'd like

It would be nice to loosen the type to unknown (with internal conditional logic).

Teachability, documentation, adoption, migration strategy

The proposed solution would simplify the client-side implementation:

try {
  // ...
} catch (cause) {
  throw new UnauthorizedException(undefined, { cause });
}

What is the motivation / use case for changing the behavior?

This would enable TypeScript users to more easily leverage Error.cause.

@namoscato namoscato added needs triage This issue has not been looked into type: enhancement 🐺 labels May 25, 2023
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@namoscato
Copy link
Contributor Author

Sure!

namoscato added a commit to namoscato/nest that referenced this issue May 26, 2023
@kamilmysliwiec
Copy link
Member

Let's track this here #11673

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

2 participants