Merge pull request #13047 from Budibase/revert-13043-fix/updating-users-via-public-api

Revert "Fix updating users via cross-service comms (public API)"
This commit is contained in:
Michael Drury 2024-02-15 13:45:04 +00:00 committed by GitHub
commit 99d72d5819
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 14 deletions

View File

@ -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
}