diff --git a/packages/core/errors/fetch-error.js b/packages/core/errors/fetch-error.js index 064d1a4cd..48bfdb7f4 100644 --- a/packages/core/errors/fetch-error.js +++ b/packages/core/errors/fetch-error.js @@ -12,14 +12,14 @@ class FetchError extends BaseError { constructor(options = {}) { const { resource, init, response, responseBody } = options; const method = init?.method ?? 'GET'; - const initText = init + let initText = init ? init.body instanceof URLSearchParams ? (() => { - init.body = init.body.toString(); - return JSON.stringify({ init }, null, 2); - })() + init.body = init.body.toString(); + return JSON.stringify({ init }, null, 2); + })() : JSON.stringify({ init }, null, 2) - : ''; + : ''; let responseBodyText = ''; if (typeof responseBody === 'string') { @@ -35,10 +35,17 @@ class FetchError extends BaseError { } } - const responseHeaderText = response + let responseHeaderText = response ? JSON.stringify({ headers: responseHeaders }, null, 2) : ''; + // sanitize error reporting + if (process.env.STAGE !== 'dev') { + initText = false; + responseHeaderText = false; + responseBodyText = false; + } + const messageParts = [ stripIndent` -----------------------------------------------------