Skip to content

Commit 085db34

Browse files
feat: 🎸 make exception filters command
1 parent f502a5b commit 085db34

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎src/commands/make.command.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,35 @@ export class MakeCommand {
121121
.cd(subdir)
122122
.render('service.empty.ts', `${names.kebabName}.service.ts`, names)
123123
}
124+
125+
@Command({
126+
name: 'make:filter <name>',
127+
description: 'Create a HTTP exception filter.',
128+
arguments: {
129+
name: 'Filter class name.',
130+
},
131+
})
132+
async filter(
133+
@Arguments()
134+
args: string[]
135+
) {
136+
const [name] = args
137+
138+
const fs = new FileSystem()
139+
140+
let root = ''
141+
if (fs.exists('app/filters')) {
142+
root = 'app/filters'
143+
} else if (fs.exists('filters')) {
144+
root = 'filters'
145+
}
146+
147+
const names = getNames(basename(name))
148+
const subdir = dirname(name)
149+
150+
fs.cd(root)
151+
.ensureDir(subdir)
152+
.cd(subdir)
153+
.render('filter.empty.ts', `${names.kebabName}.exception.filter.ts`, names)
154+
}
124155
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Catch, ExceptionFilter } from "@smoothjs/smooth";
2+
3+
@Catch()
4+
export class /* upperFirstCamelName */ implements ExceptionFilter {
5+
async catch(
6+
exception: any,
7+
response: any,
8+
) {
9+
response.send('Hello World')
10+
}
11+
}

0 commit comments

Comments
 (0)