mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:25:52 +00:00
chore(gateway): report error with cause message (#3999)
This commit is contained in:
parent
320005843a
commit
6595fde713
@ -165,8 +165,8 @@ describe('gateway', () => {
|
||||
wsClient.on('open', resolve);
|
||||
});
|
||||
};
|
||||
const getLastMessage = () => {
|
||||
return JSON.parse(messages[messages.length - 1]);
|
||||
const getLastMessage = (n = 0) => {
|
||||
return JSON.parse(messages[messages.length - (1 + n)]);
|
||||
};
|
||||
const clearMessages = () => {
|
||||
messages = [];
|
||||
@ -377,5 +377,32 @@ describe('gateway', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
it('should receive error message with cause property', async () => {
|
||||
await connectClient(port);
|
||||
const app = new Application({
|
||||
database: {
|
||||
dialect: 'sqlite',
|
||||
storage: ':memory:',
|
||||
},
|
||||
});
|
||||
await waitSecond();
|
||||
await app.runCommand('start');
|
||||
await app.runCommand('install');
|
||||
await waitSecond();
|
||||
expect(getLastMessage()).toMatchObject({
|
||||
type: 'maintaining',
|
||||
payload: {
|
||||
code: 'APP_RUNNING',
|
||||
},
|
||||
});
|
||||
await app.runAsCLI(['pm', 'add', 'not-exists-plugin'], {
|
||||
from: 'user',
|
||||
});
|
||||
await waitSecond();
|
||||
const errorMsg = getLastMessage(1);
|
||||
expect(errorMsg.type).toBe('notification');
|
||||
expect(errorMsg.payload.type).toBe('error');
|
||||
expect(errorMsg.payload.message).contains('Failed to add plugin:');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -765,6 +765,8 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
|
||||
if (options?.throwError) {
|
||||
throw error;
|
||||
} else {
|
||||
this.log.error(error);
|
||||
}
|
||||
} finally {
|
||||
const _actionCommand = this._actionCommand;
|
||||
|
@ -62,10 +62,16 @@ export class WSServer {
|
||||
});
|
||||
|
||||
AppSupervisor.getInstance().on('appError', async ({ appName, error }) => {
|
||||
let message = error.message;
|
||||
|
||||
if (error.cause) {
|
||||
message = `${message}: ${error.cause.message}`;
|
||||
}
|
||||
|
||||
this.sendToConnectionsByTag('app', appName, {
|
||||
type: 'notification',
|
||||
payload: {
|
||||
message: error.message,
|
||||
message,
|
||||
type: 'error',
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user