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

How to prevent got from logging request details on error #2359

Closed
goleary opened this issue Jun 14, 2024 · 1 comment
Closed

How to prevent got from logging request details on error #2359

goleary opened this issue Jun 14, 2024 · 1 comment

Comments

@goleary
Copy link

goleary commented Jun 14, 2024

We have a proxy-like endpoint where users can upload files to another service. We use GOT to execute the PUT request. When the external service response 413 (PAYLOAD_TOO_LARGE) got then logs the entire request. Because this request payload is ~40mb this data is written to our console and causes our app to crash.

We are not logging the request, it seems like got is doing this internally. Is there some way to turn this behavior off for a specific request? (or entirely) so that our backend doesn't blowup?

image

Thanks!

@goleary goleary changed the title How to prevent GOT from logging request details on error How to prevent got from logging request details on error Jun 14, 2024
@goleary
Copy link
Author

goleary commented Jun 14, 2024

Figured it out. I can simply overwrite the body in beforeError

got.extend({
  beforeError: [
    (error) => {
      if (
        error.response?.statusCode === HTTP_STATUS_CODES.PAYLOAD_TOO_LARGE
      ) {
        error.options.body = "REDACTED";
      }
      return error;
    }
  ]
});

@goleary goleary closed this as completed Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant