From 74957725dd08eeb97a3ba7bef6bf9a97e32e56d3 Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Thu, 15 Feb 2024 13:44:43 +0000 Subject: [PATCH] Revert "Fix updating users via cross-service comms (public API)" --- .../server/src/utilities/workerRequests.ts | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/server/src/utilities/workerRequests.ts b/packages/server/src/utilities/workerRequests.ts index 5612084216..69ce58c8a9 100644 --- a/packages/server/src/utilities/workerRequests.ts +++ b/packages/server/src/utilities/workerRequests.ts @@ -14,23 +14,12 @@ export function request(ctx?: Ctx, request?: any) { if (!request.headers) { request.headers = {} } - if (!ctx) { request.headers[constants.Header.API_KEY] = coreEnv.INTERNAL_API_KEY - } else if (ctx.headers) { - // copy all Budibase utilised headers over - copying everything can have - // side effects like requests being rejected due to odd content types etc - for (let header of Object.values(constants.Header)) { - if (ctx.headers[header]) { - request.headers[header] = ctx.headers[header] - } + if (tenancy.isTenantIdSet()) { + request.headers[constants.Header.TENANT_ID] = tenancy.getTenantId() } } - - // apply tenancy if its available - if (tenancy.isTenantIdSet()) { - request.headers[constants.Header.TENANT_ID] = tenancy.getTenantId() - } if (request.body && Object.keys(request.body).length > 0) { request.headers["Content-Type"] = "application/json" request.body = @@ -40,6 +29,9 @@ export function request(ctx?: Ctx, request?: any) { } else { delete request.body } + if (ctx && ctx.headers) { + request.headers = ctx.headers + } // add x-budibase-correlation-id header logging.correlation.setHeader(request.headers) @@ -62,7 +54,7 @@ async function checkResponse( } const msg = `Unable to ${errorMsg} - ${responseErrorMessage}` if (ctx) { - ctx.throw(response.status || 500, msg) + ctx.throw(msg, response.status) } else { throw msg }