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

Different error message for dev and prod environments #67

Closed
ilzrv opened this issue Oct 4, 2021 · 6 comments
Closed

Different error message for dev and prod environments #67

ilzrv opened this issue Oct 4, 2021 · 6 comments
Labels
kind/support Support request resolution/wontfix This will not be worked on

Comments

@ilzrv
Copy link

ilzrv commented Oct 4, 2021

Is there a way for different environments (development, production) to use different error descriptions?

For example, in a dev environment, errors can be displayed completely:

{
    "code": "internal",
    "msg": "internal error",
    "meta": {
        "cause": "Secret Exception Message"
    }
}

But in the prod environment the original error message should be hidden:

{
    "code": "internal",
    "msg": "internal error",
    "meta": {
        "cause": "Internal Server Error"
    }
}

Is there any possibility to implement this?

@sagikazarmark
Copy link
Member

I don't think that's possible with the library at the moment. However, I don't think that's a good practice either.

For one, it would be the source of all kinds of confusion why the app behaves differently in dev.
Secondly, having different habits for debugging service-to-service communication in dev and prod can also easily lead to problems when the house is on fire.

@ilzrv
Copy link
Author

ilzrv commented Oct 4, 2021

If this is used on the site frontend, it's not safe to show real error messages. Don't you think so?

@sagikazarmark
Copy link
Member

It depends on the errors. Secret Exception Message suggests it's an internal error. No, I don't think that should ever be shown on a frontend.

If it's a business error though (eg. some resource cannot be found), you can convert the error to a Twirp error, specifying a message and an error code. But I assume this is not the case here.

@ilzrv
Copy link
Author

ilzrv commented Oct 4, 2021

If it's a business error though (eg. some resource cannot be found), you can convert the error to a Twirp error, specifying a message and an error code. But I assume this is not the case here.

Are you talking about errors that I throw myself(TwirpError)?

@the-toster
Copy link

I think it's possible by passing custom response factory to the generated server constructor.

@sagikazarmark
Copy link
Member

Are you talking about errors that I throw myself(TwirpError)?

Yes, you should convert business errors to twirp errors manually.

I think it's possible by passing custom response factory to the generated server constructor.

Yep, that's one way to do it. Implementing interceptors might also be a good way.

I'm closing this issue for now. If you want to continue the discussion, please start a new one under Discussions. Thanks!

@sagikazarmark sagikazarmark added kind/support Support request resolution/wontfix This will not be worked on labels Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Support request resolution/wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants