File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 1
1
const ValidationError = require ( '../errors/ValidationError' ) ;
2
2
const DockerService = require ( '../services/DockerService' ) ;
3
3
const extractYaml = require ( '../helpers/extractYaml' ) ;
4
+ const handler = require ( '../helpers/handler' ) ;
4
5
5
6
class DockerController {
6
- static async applyYaml ( req , res , next ) {
7
- try {
7
+ static async applyYaml ( req , res ) {
8
8
const file = extractYaml ( req . files ) ;
9
9
if ( ! file ) {
10
- next ( new ValidationError ( 'no file provided' ) ) ;
11
- return ;
10
+ throw new ValidationError ( 'no file provided' ) ;
12
11
}
13
12
14
13
const result = await DockerService . applyYaml ( file . data . toString ( ) ) ;
15
14
res . json ( result ) ;
16
- } catch ( e ) {
17
- next ( e ) ;
18
- }
19
15
}
20
16
}
21
17
22
- module . exports = DockerController ;
18
+ module . exports = handler ( DockerController ) ;
23
19
24
20
Original file line number Diff line number Diff line change
1
+ module . exports = function ( controller ) {
2
+ for ( const property of Object . getOwnPropertyNames ( controller ) ) {
3
+ let endpoint = controller [ property ] ;
4
+ if ( typeof endpoint === 'function' ) {
5
+ controller [ property ] = async function ( req , res , next ) {
6
+ try {
7
+ await endpoint ( req , res , next ) ;
8
+ } catch ( e ) {
9
+ next ( e )
10
+ }
11
+ }
12
+ }
13
+ }
14
+ return controller ;
15
+ } ;
You can’t perform that action at this time.
0 commit comments