fix(mindspace): map publication RPC errors to HTTP status codes
Return 404/401/403 from MindSpace RPC for known publication errors and preserve error codes through the Portal remote adapter. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -27,17 +27,32 @@ function buildRemoteOperationUrl(endpoint, bindingKey, method, operationBasePath
|
||||
return `${base}${normalizedBasePath}/${encodeURIComponent(bindingKey)}/${encodeURIComponent(method)}`;
|
||||
}
|
||||
|
||||
async function parseRemoteOperationResponse(response, bindingKey, method) {
|
||||
if (!response.ok) {
|
||||
const bodyText = await response.text().catch(() => '');
|
||||
throw new Error(
|
||||
function throwRemoteOperationError(response, bindingKey, method, bodyText, payload) {
|
||||
const error = new Error(
|
||||
payload?.message ??
|
||||
`MindSpace remote adapter ${bindingKey}.${method}() failed with ${response.status}${bodyText ? `: ${bodyText}` : ''}`,
|
||||
);
|
||||
);
|
||||
if (payload?.code) error.code = payload.code;
|
||||
if (payload?.details !== undefined) error.details = payload.details;
|
||||
throw error;
|
||||
}
|
||||
|
||||
async function parseRemoteOperationResponse(response, bindingKey, method) {
|
||||
const bodyText = await response.text().catch(() => '');
|
||||
let payload = null;
|
||||
if (bodyText) {
|
||||
try {
|
||||
payload = JSON.parse(bodyText);
|
||||
} catch {
|
||||
payload = null;
|
||||
}
|
||||
}
|
||||
if (!response.ok) {
|
||||
throwRemoteOperationError(response, bindingKey, method, bodyText, payload);
|
||||
}
|
||||
if (response.status === 204) return null;
|
||||
const text = await response.text();
|
||||
if (!text) return null;
|
||||
return JSON.parse(text);
|
||||
if (!bodyText) return null;
|
||||
return payload ?? JSON.parse(bodyText);
|
||||
}
|
||||
|
||||
async function invokeRemoteOperation({
|
||||
|
||||
Reference in New Issue
Block a user