Commit 07b39724 authored by nanahira's avatar nanahira

adapt SessionError changes

parent 6e65943a
This diff is collapsed.
......@@ -33,7 +33,7 @@
"peerDependencies": {
"@nestjs/common": "^9.0.3 || ^8.0.0",
"@nestjs/core": "^9.0.3 || ^8.0.0",
"koishi": "^4.9.7",
"koishi": "^4.10.1",
"rxjs": "^7.5.5"
},
"devDependencies": {
......
......@@ -5,6 +5,7 @@ import {
Injectable,
} from '@nestjs/common';
import { WsException } from '@nestjs/websockets';
import { SessionError } from 'koishi';
import { KOISHI_MODULE_OPTIONS } from '../utility/koishi.constants';
import { KoishiModuleOptions } from '../utility/koishi.interfaces';
......@@ -18,16 +19,19 @@ export class KoishiExceptionHandlerService extends ConsoleLogger {
}
handleActionException(e: Error) {
if (e instanceof SessionError) {
console.log('session error');
throw e;
}
if (e instanceof HttpException || e instanceof WsException) {
return e.message;
} else {
this.error(e.message, e.stack);
if (this.koishiModuleOptions.actionErrorMessage === '') {
return;
}
return (
this.koishiModuleOptions.actionErrorMessage ?? 'Internal Server Error'
);
}
this.error(e.message, e.stack);
if (this.koishiModuleOptions.actionErrorMessage === '') {
return;
}
return (
this.koishiModuleOptions.actionErrorMessage ?? 'Internal Server Error'
);
}
}
import { HttpException } from '@nestjs/common';
import { WsException } from '@nestjs/websockets';
export function handleActionException(e: Error) {
if (e instanceof HttpException || e instanceof WsException) {
return e.message;
} else {
throw e;
}
}
......@@ -165,6 +165,16 @@ describe('Koishi in Nest.js', () => {
);
});
/*
it('should handle SessionError', () => {
const command = koishiApp.command('hoo');
expect(command).toBeDefined();
expect(command.execute({ options: { content: 'hoo' } })).resolves.toBe(
'hoo!',
);
});
*/
it('should work on template', () => {
const command = koishiApp.command('mii');
expect(command).toBeDefined();
......
import { Injectable, NotFoundException } from '@nestjs/common';
import { KoishiCommandInterceptor } from '../../src/utility/koishi.interfaces';
import { Argv, Context } from 'koishi';
import { Argv, Context, SessionError } from 'koishi';
import {
CommandTemplate,
CommandUsage,
OnGuild,
OnPlatform,
......@@ -74,6 +75,12 @@ export class KoishiTestService {
throw new Error('bow!');
}
@UseCommand('hoo')
@CommandTemplate('.hoo', 'hoo!')
async onHoo() {
throw new SessionError('.hoo');
}
@UseCommand('moo')
@CommandInterceptors(MooInterceptor)
async onMoo() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment