Skip to content

Commit 7635abc

Browse files
authored
Use kubevirt error message on VM action error (stolostron#3901)
* Use kubevirt error message on VM action error Signed-off-by: zlayne <zlayne@redhat.com> * Better unauthorized message Signed-off-by: zlayne <zlayne@redhat.com> * update console error namsepace Signed-off-by: zlayne <zlayne@redhat.com> * update test Signed-off-by: zlayne <zlayne@redhat.com> --------- Signed-off-by: zlayne <zlayne@redhat.com>
1 parent fe25101 commit 7635abc

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

backend/src/lib/json-request.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ export interface PostResponse<T> {
2727
export interface PutResponse {
2828
statusCode?: number
2929
body?: {
30+
kind?: string
3031
name?: string
3132
message?: string
33+
reason?: string
34+
code?: number
3235
}
3336
}
3437

backend/src/routes/virtualMachineProxy.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function virtualMachineProxy(req: Http2ServerRequest, res: Http2Ser
4646
return Buffer.from(proxyToken, 'base64').toString('ascii')
4747
})
4848
.catch((err: Error): undefined => {
49-
logger.error({ msg: `Error getting secret in namespace bare-metal`, error: err.message })
49+
logger.error({ msg: `Error getting secret in namespace ${body.managedCluster}`, error: err.message })
5050
return undefined
5151
})
5252

@@ -86,7 +86,10 @@ export async function virtualMachineProxy(req: Http2ServerRequest, res: Http2Ser
8686
msg: 'Error in VirtualMachine action response',
8787
error: results.body.message,
8888
})
89-
res.writeHead(results.statusCode ?? HTTP_STATUS_INTERNAL_SERVER_ERROR).end(JSON.stringify(results))
89+
res.setHeader('Content-Type', 'application/json')
90+
res.writeHead(results.statusCode ?? HTTP_STATUS_INTERNAL_SERVER_ERROR)
91+
delete results.body?.code // code is added via writeHead
92+
res.end(JSON.stringify(results.body))
9093
}
9194
})
9295
.catch((err: Error) => {

backend/test/routes/virtualMachineProxy.test.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,8 @@ describe('Virtual Machine actions', function () {
131131
expect(res.statusCode).toEqual(500)
132132
expect(JSON.stringify(await parsePipedJsonBody(res))).toEqual(
133133
JSON.stringify({
134-
statusCode: 500,
135-
body: {
136-
name: 'fetchError',
137-
message: 'error testing...',
138-
},
134+
name: 'fetchError',
135+
message: 'error testing...',
139136
})
140137
)
141138
})

frontend/public/locales/en/translation.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,6 @@
13641364
"error": "Error",
13651365
"Error": "Error",
13661366
"Error getting Ansible jobs": "Error getting Ansible jobs",
1367-
"Error occurred on VirtualMachine {{name}} {{action}} action.": "Error occurred on VirtualMachine {{name}} {{action}} action.",
13681367
"Error occurred while contacting the search service.": "Error occurred while contacting the search service.",
13691368
"Error occurred while getting the result count.": "Error occurred while getting the result count.",
13701369
"Error occurred while querying for search results. Please try the export again.": "Error occurred while querying for search results. Please try the export again.",
@@ -1373,6 +1372,7 @@
13731372
"Error querying for VirtualMachines": "Error querying for VirtualMachines",
13741373
"Error querying resource logs:": "Error querying resource logs:",
13751374
"Error querying search results": "Error querying search results",
1375+
"Error triggering action {{action}} on VirtualMachine {{name}}": "Error triggering action {{action}} on VirtualMachine {{name}}",
13761376
"error.create.syntax": "Syntax error: {{0}}",
13771377
"Etcd storage class": "Etcd storage class",
13781378
"Ev3-series": "Ev3-series",
@@ -3047,6 +3047,7 @@
30473047
"Unable to communicate with the server due to a gateway timeout.": "Unable to communicate with the server due to a gateway timeout.",
30483048
"Unable to update the resource because of a resource conflict.": "Unable to update the resource because of a resource conflict.",
30493049
"Unauthorized": "Unauthorized",
3050+
"Unauthorized to execute this action.": "Unauthorized to execute this action.",
30503051
"unavailable": "unavailable",
30513052
"Unavailable": "Unavailable",
30523053
"unbind": "Remove from cluster",
@@ -3067,7 +3068,6 @@
30673068
"unknown: {{count}} cluster_plural": "unknown: {{count}} clusters",
30683069
"Unpause {{resourceKind}}": "Unpause {{resourceKind}}",
30693070
"Unprocessable entity": "Unprocessable entity",
3070-
"Unsuccessful request": "Unsuccessful request",
30713071
"update": "Update",
30723072
"Update automation template": "Update automation template",
30733073
"Update risk predictions": "Update risk predictions",

frontend/src/routes/Search/SearchResults/utils.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ export function handleVMActions(
5454
})
5555
.catch((err) => {
5656
console.error(`VirtualMachine: ${item.name} ${action} error. ${err}`)
57+
58+
let errMessage = err?.message ?? t('An unexpected error occurred.')
59+
if (errMessage.includes(':')) errMessage = errMessage.split(':')[1]
60+
if (errMessage === 'Unauthorized') errMessage = t('Unauthorized to execute this action.')
5761
toast.addAlert({
58-
title: err?.message ?? t('Unsuccessful request'),
59-
message: t('Error occurred on VirtualMachine {{name}} {{action}} action.', {
62+
title: t('Error triggering action {{action}} on VirtualMachine {{name}}', {
6063
name: item.name,
6164
action,
6265
}),
66+
message: errMessage,
6367
type: 'danger',
6468
})
6569
})

0 commit comments

Comments
 (0)