From b35f0f0d5cf34d636952131f245f6e7870cf7e07 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 19 Feb 2021 13:17:10 -0800 Subject: [PATCH] Debug Logs: Log response body when we fail to upload --- ts/logging/debuglogs.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ts/logging/debuglogs.ts b/ts/logging/debuglogs.ts index 36d01c0497..bce9cce41d 100644 --- a/ts/logging/debuglogs.ts +++ b/ts/logging/debuglogs.ts @@ -4,7 +4,7 @@ import FormData from 'form-data'; import { gzip } from 'zlib'; import pify from 'pify'; -import got from 'got'; +import got, { Response } from 'got'; import { getUserAgent } from '../util/getUserAgent'; const BASE_URL = 'https://debuglogs.org'; @@ -68,9 +68,18 @@ export const uploadDebugLogs = async ( }); window.log.info('Debug log upload starting...'); - const { statusCode } = await got.post(url, { headers, body: form }); - if (statusCode !== 204) { - throw new Error(`Failed to upload to S3, got status ${statusCode}`); + try { + const { statusCode, body } = await got.post(url, { headers, body: form }); + if (statusCode !== 204) { + throw new Error( + `Failed to upload to S3, got status ${statusCode}, body '${body}'` + ); + } + } catch (error) { + const response = error.response as Response; + throw new Error( + `Got threw on upload to S3, got status ${response?.statusCode}, body '${response?.body}' ` + ); } window.log.info('Debug log upload complete.');