Copilot commented on code in PR #12412:
URL: https://github.com/apache/cloudstack/pull/12412#discussion_r2693122560


##########
ui/src/utils/plugins.js:
##########
@@ -218,18 +218,19 @@ export const notifierPlugin = {
         if (error.response.status) {
           msg = `${i18n.global.t('message.request.failed')} 
(${error.response.status})`
         }
-        if (error.message) {
-          desc = error.message
-        }
-        if (error.response.headers && 'x-description' in 
error.response.headers) {
+        if (error.response.headers?.['x-description']) {
           desc = error.response.headers['x-description']
-        }
-        if (desc === '' && error.response.data) {
+        } else if (error.response.data) {

Review Comment:
   The condition check `else if (error.response.data)` is too broad and will 
evaluate to true for empty objects or arrays. This could lead to unnecessary 
processing of the response data block when there's no actual data. Consider 
using a more specific check like `else if (error.response.data && 
Object.keys(error.response.data).length > 0)` or checking for truthy values 
that actually contain data.
   ```suggestion
           } else if (error.response.data && (typeof error.response.data !== 
'object' || Object.keys(error.response.data).length > 0)) {
   ```



##########
ui/src/utils/plugins.js:
##########
@@ -218,18 +218,19 @@ export const notifierPlugin = {
         if (error.response.status) {
           msg = `${i18n.global.t('message.request.failed')} 
(${error.response.status})`
         }
-        if (error.message) {
-          desc = error.message
-        }
-        if (error.response.headers && 'x-description' in 
error.response.headers) {
+        if (error.response.headers?.['x-description']) {
           desc = error.response.headers['x-description']
-        }
-        if (desc === '' && error.response.data) {
+        } else if (error.response.data) {
           const responseKey = _.findKey(error.response.data, 'errortext')
           if (responseKey) {
             desc = error.response.data[responseKey].errortext
+          } else if (typeof error.response.data === 'string') {
+            desc = error.response.data

Review Comment:
   String responses should be trimmed before assignment to avoid displaying 
empty or whitespace-only error messages. Consider using `desc = 
error.response.data.trim()` and only assigning if the trimmed result is 
non-empty.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to