mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 11:39:26 +01:00
fix: surface actual error message when service installation fails
Backend returned { error: message } on 400 but frontend expected { message }.
catchInternal swallowed Axios errors and returned undefined, causing a
generic 'An internal error occurred' message instead of the real reason
(already installed, already in progress, not found).
- Fix 400 response shape to { success: false, message } in controller
- Replace catchInternal with direct error handling in installService,
affectService, and forceReinstallService API methods
- Extract error.response.data.message from Axios errors so callers
see the actual server message
This commit is contained in:
parent
5113cc3eed
commit
8529662cdf
|
|
@ -35,7 +35,7 @@ export default class SystemController {
|
|||
if (result.success) {
|
||||
response.send({ success: true, message: result.message });
|
||||
} else {
|
||||
response.status(400).send({ error: result.message });
|
||||
response.status(400).send({ success: false, message: result.message });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import axios, { AxiosInstance } from 'axios'
|
||||
import axios, { AxiosError, AxiosInstance } from 'axios'
|
||||
import { ListRemoteZimFilesResponse, ListZimFilesResponse } from '../../types/zim'
|
||||
import { ServiceSlim } from '../../types/services'
|
||||
import { FileEntry } from '../../types/files'
|
||||
|
|
@ -25,13 +25,19 @@ class API {
|
|||
}
|
||||
|
||||
async affectService(service_name: string, action: 'start' | 'stop' | 'restart') {
|
||||
return catchInternal(async () => {
|
||||
try {
|
||||
const response = await this.client.post<{ success: boolean; message: string }>(
|
||||
'/system/services/affect',
|
||||
{ service_name, action }
|
||||
)
|
||||
return response.data
|
||||
})()
|
||||
} catch (error) {
|
||||
if (error instanceof AxiosError && error.response?.data?.message) {
|
||||
return { success: false, message: error.response.data.message }
|
||||
}
|
||||
console.error('Error affecting service:', error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
async checkLatestVersion(force: boolean = false) {
|
||||
|
|
@ -192,13 +198,19 @@ class API {
|
|||
}
|
||||
|
||||
async forceReinstallService(service_name: string) {
|
||||
return catchInternal(async () => {
|
||||
try {
|
||||
const response = await this.client.post<{ success: boolean; message: string }>(
|
||||
`/system/services/force-reinstall`,
|
||||
{ service_name }
|
||||
)
|
||||
return response.data
|
||||
})()
|
||||
} catch (error) {
|
||||
if (error instanceof AxiosError && error.response?.data?.message) {
|
||||
return { success: false, message: error.response.data.message }
|
||||
}
|
||||
console.error('Error force reinstalling service:', error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
async getChatSuggestions(signal?: AbortSignal) {
|
||||
|
|
@ -452,13 +464,19 @@ class API {
|
|||
}
|
||||
|
||||
async installService(service_name: string) {
|
||||
return catchInternal(async () => {
|
||||
try {
|
||||
const response = await this.client.post<{ success: boolean; message: string }>(
|
||||
'/system/services/install',
|
||||
{ service_name }
|
||||
)
|
||||
return response.data
|
||||
})()
|
||||
} catch (error) {
|
||||
if (error instanceof AxiosError && error.response?.data?.message) {
|
||||
return { success: false, message: error.response.data.message }
|
||||
}
|
||||
console.error('Error installing service:', error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
async listCuratedMapCollections() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user