fix: Error processing and output pane improvements (no-changelog) (#9626)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Michael Kret
2024-06-27 13:22:07 +03:00
committed by GitHub
parent a43d6f0c5e
commit 4773aad170
9 changed files with 47 additions and 22 deletions

View File

@@ -39,8 +39,9 @@ interface NodeApiErrorOptions extends NodeOperationErrorOptions {
/**
* Top-level properties where an error message can be found in an API response.
* order is important, precedence is from top to bottom
*/
const ERROR_MESSAGE_PROPERTIES = [
const POSSIBLE_ERROR_MESSAGE_KEYS = [
'cause',
'error',
'message',
@@ -60,6 +61,7 @@ const ERROR_MESSAGE_PROPERTIES = [
'errorDescription',
'error_description',
'error_summary',
'error_info',
'title',
'text',
'field',
@@ -67,10 +69,15 @@ const ERROR_MESSAGE_PROPERTIES = [
'type',
];
/**
* Properties where a nested object can be found in an API response.
*/
const POSSIBLE_NESTED_ERROR_OBJECT_KEYS = ['Error', 'error', 'err', 'response', 'body', 'data'];
/**
* Top-level properties where an HTTP error code can be found in an API response.
*/
const ERROR_STATUS_PROPERTIES = [
const POSSIBLE_ERROR_STATUS_KEYS = [
'statusCode',
'status',
'code',
@@ -79,11 +86,6 @@ const ERROR_STATUS_PROPERTIES = [
'error_code',
];
/**
* Properties where a nested object can be found in an API response.
*/
const ERROR_NESTING_PROPERTIES = ['error', 'err', 'response', 'body', 'data'];
/**
* Descriptive messages for common HTTP status codes
* this is used by NodeApiError class
@@ -187,7 +189,11 @@ export class NodeApiError extends NodeError {
this.httpCode = errorResponse.httpCode as string;
} else {
this.httpCode =
this.findProperty(errorResponse, ERROR_STATUS_PROPERTIES, ERROR_NESTING_PROPERTIES) ?? null;
this.findProperty(
errorResponse,
POSSIBLE_ERROR_STATUS_KEYS,
POSSIBLE_NESTED_ERROR_OBJECT_KEYS,
) ?? null;
}
this.level = level ?? 'warning';
@@ -222,8 +228,8 @@ export class NodeApiError extends NodeError {
} else {
this.description = this.findProperty(
errorResponse,
ERROR_MESSAGE_PROPERTIES,
ERROR_NESTING_PROPERTIES,
POSSIBLE_ERROR_MESSAGE_KEYS,
POSSIBLE_NESTED_ERROR_OBJECT_KEYS,
);
}
}
@@ -266,8 +272,8 @@ export class NodeApiError extends NodeError {
const topLevelKey = Object.keys(result)[0];
this.description = this.findProperty(
result[topLevelKey],
ERROR_MESSAGE_PROPERTIES,
['Error'].concat(ERROR_NESTING_PROPERTIES),
POSSIBLE_ERROR_MESSAGE_KEYS,
POSSIBLE_NESTED_ERROR_OBJECT_KEYS,
);
});
}