Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Nestjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
Koishi Nestjs
Commits
07b39724
Commit
07b39724
authored
Nov 14, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adapt SessionError changes
parent
6e65943a
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
122 additions
and
111 deletions
+122
-111
package-lock.json
package-lock.json
+91
-91
package.json
package.json
+1
-1
src/koishi-exception-handler/koishi-exception-handler.service.ts
...shi-exception-handler/koishi-exception-handler.service.ts
+12
-8
src/utility/wrap-action.ts
src/utility/wrap-action.ts
+0
-10
tests/koishi-tests.spec.ts
tests/koishi-tests.spec.ts
+10
-0
tests/utility/testing-module.ts
tests/utility/testing-module.ts
+8
-1
No files found.
package-lock.json
View file @
07b39724
This diff is collapsed.
Click to expand it.
package.json
View file @
07b39724
...
...
@@ -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"
:
{
...
...
src/koishi-exception-handler/koishi-exception-handler.service.ts
View file @
07b39724
...
...
@@ -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
'
);
}
}
src/utility/wrap-action.ts
deleted
100644 → 0
View file @
6e65943a
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
;
}
}
tests/koishi-tests.spec.ts
View file @
07b39724
...
...
@@ -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
();
...
...
tests/utility/testing-module.ts
View file @
07b39724
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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment