There was an issue where extra headers were being carried over to the worker instance when performing cross-service comms - these headers were causing the request to be rejected without consideration. Cleaning up to only include the headers Budibase really cares about in request, let fetch work out the generic ones.

This commit is contained in:
mike12345567 2024-02-15 12:49:39 +00:00
parent dea72b5818
commit d3bb8b2fa4
1 changed files with 14 additions and 6 deletions

View File

@ -14,12 +14,23 @@ export function request(ctx?: Ctx, request?: any) {
if (!request.headers) {
request.headers = {}
}
if (!ctx) {
request.headers[constants.Header.API_KEY] = coreEnv.INTERNAL_API_KEY
if (tenancy.isTenantIdSet()) {
request.headers[constants.Header.TENANT_ID] = tenancy.getTenantId()
} else {
// 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]
}
}
}
// 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 =
@ -29,9 +40,6 @@ 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)
@ -54,7 +62,7 @@ async function checkResponse(
}
const msg = `Unable to ${errorMsg} - ${responseErrorMessage}`
if (ctx) {
ctx.throw(msg, response.status)
ctx.throw(response.status || 500, msg)
} else {
throw msg
}