Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit e3502ad

Browse files
dwirzbuehler
authored andcommitted
fix(errorhandler): Await the promise before returning on response params (#131)
1 parent b1b1f6c commit e3502ad

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

src/Giuseppe.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import { ControllerMetadata } from './utilities/ControllerMetadata';
2626
/**
2727
* Score sort function for route register information. Calculates the sorting score based on segments, url params
2828
* and wildcards.
29-
*
30-
* @param {RouteRegisterInformation} route
29+
*
30+
* @param {RouteRegisterInformation} route
3131
*/
3232
const routeScore = (route: RouteRegisterInformation) =>
3333
route.segments * 1000 - route.urlParams * 0.001 - route.wildcards;
@@ -49,15 +49,15 @@ export interface RouteRegisterInformation {
4949
/**
5050
* Main entry class for giuseppe. Does contain the necessary methods to get the application running.
5151
* Does export the configuration and plugin system.
52-
*
52+
*
5353
* @export
5454
* @class Giuseppe
5555
*/
5656
export class Giuseppe {
5757
/**
5858
* Giuseppes item registrar. Is used to register controllers, routes, parameters and all other things that
5959
* giuseppe contains. Can be used even when giuseppe is not instantiated yet.
60-
*
60+
*
6161
* @static
6262
* @type {GiuseppeRegistrar}
6363
* @memberof Giuseppe
@@ -66,7 +66,7 @@ export class Giuseppe {
6666

6767
/**
6868
* The actual server instance of express once the application has started.
69-
*
69+
*
7070
* @readonly
7171
* @type {(Server | undefined)}
7272
* @memberof Giuseppe
@@ -79,7 +79,7 @@ export class Giuseppe {
7979
* The express application behind this instance of giuseppe. Someone might want to change the used express instance
8080
* before calling [start()]{@link Giuseppe#start()}. Also, on this propert you can add other things like
8181
* compression or body-parser.
82-
*
82+
*
8383
* @type {express.Express}
8484
* @memberof Giuseppe
8585
*/
@@ -88,7 +88,7 @@ export class Giuseppe {
8888
/**
8989
* The router instance that is used for this instance of giuseppe. Access it to add additional routes or even
9090
* switch the whole router.
91-
*
91+
*
9292
* @type {express.Router}
9393
* @memberof Giuseppe
9494
*/
@@ -106,7 +106,7 @@ export class Giuseppe {
106106

107107
/**
108108
* List of registered {@link ReturnType}.
109-
*
109+
*
110110
* @readonly
111111
* @protected
112112
* @type {ReturnType<any>[]}
@@ -123,7 +123,7 @@ export class Giuseppe {
123123

124124
/**
125125
* List of registered {@link ControllerDefinitionConstructor}.
126-
*
126+
*
127127
* @readonly
128128
* @protected
129129
* @type {ControllerDefinitionConstructor[]}
@@ -140,7 +140,7 @@ export class Giuseppe {
140140

141141
/**
142142
* List of registered {@link RouteDefinitionConstructor}.
143-
*
143+
*
144144
* @readonly
145145
* @protected
146146
* @type {RouteDefinitionConstructor[]}
@@ -157,7 +157,7 @@ export class Giuseppe {
157157

158158
/**
159159
* List of registered {@link RouteModificatorConstructor}.
160-
*
160+
*
161161
* @readonly
162162
* @protected
163163
* @type {RouteModificatorConstructor[]}
@@ -174,7 +174,7 @@ export class Giuseppe {
174174

175175
/**
176176
* List of registered {@link ParameterDefinitionConstructor}.
177-
*
177+
*
178178
* @readonly
179179
* @protected
180180
* @type {ParameterDefinitionConstructor[]}
@@ -196,9 +196,9 @@ export class Giuseppe {
196196
/**
197197
* Registers a given plugin into this giuseppe instance. Clears the internal caches when it does so.
198198
* Calls the initialize method on a plugin.
199-
*
200-
* @param {GiuseppePlugin} plugin
201-
* @returns {this}
199+
*
200+
* @param {GiuseppePlugin} plugin
201+
* @returns {this}
202202
* @memberof Giuseppe
203203
*/
204204
public registerPlugin(plugin: GiuseppePlugin): this {
@@ -221,7 +221,7 @@ export class Giuseppe {
221221
* Fires up the express application within giuseppe. Gathers all registered controllers and routes and registers
222222
* them on the given [router]{@link Giuseppe#router}. After the router is configured, fires up the express
223223
* application with the given parameter.
224-
*
224+
*
225225
* @param {number} [port=8080] The port of the web application (express.listen argument).
226226
* @param {string} [baseUrl=''] Base url that is preceeding all urls in the system.
227227
* @param {string} [hostname] Hostname that is passed to express.
@@ -236,7 +236,7 @@ export class Giuseppe {
236236

237237
/**
238238
* Closes the server of the application.
239-
*
239+
*
240240
* @param {Function} [callback] Callback that is passed to the server.
241241
* @memberof Giuseppe
242242
*/
@@ -253,9 +253,9 @@ export class Giuseppe {
253253
* More information here: [glob]{@link https://www.npmjs.com/package/glob#glob-primer}.
254254
*
255255
* Can be used when you don't want to load all controllers by hand.
256-
*
257-
* @param {string} globPattern
258-
* @returns {Promise<void>}
256+
*
257+
* @param {string} globPattern
258+
* @returns {Promise<void>}
259259
* @memberof Giuseppe
260260
*
261261
* @example
@@ -292,7 +292,7 @@ export class Giuseppe {
292292
/**
293293
* Configures the actual instance of the express router. Creates the registered routes for the controllers in giuseppe
294294
* as the first step. After that, registers each route to the router and returns the router.
295-
*
295+
*
296296
* @param {string} [baseUrl=''] Base url, that is preceeding all routes.
297297
* @returns {express.Router} The configured router.
298298
* @memberof Giuseppe
@@ -314,9 +314,9 @@ export class Giuseppe {
314314
* - If there are any, throw the routes at the modificators (can be multiple)
315315
* - Add routes to the list
316316
* 4. Create {@link RouteRegisterInformation} for each route
317-
*
317+
*
318318
* @protected
319-
* @param {string} baseUrl
319+
* @param {string} baseUrl
320320
* @memberof Giuseppe
321321
*/
322322
protected createRoutes(baseUrl: string): void {
@@ -375,10 +375,10 @@ export class Giuseppe {
375375
* ensures the right `this` context, does parse the actual param values and handles errors.
376376
*
377377
* The resulting function is then passed to the express router.
378-
*
378+
*
379379
* @protected
380-
* @param {RouteRegisterInformation} routeInfo
381-
* @returns {express.RequestHandler}
380+
* @param {RouteRegisterInformation} routeInfo
381+
* @returns {express.RequestHandler}
382382
* @memberof Giuseppe
383383
*/
384384
protected createRouteWrapper(routeInfo: RouteRegisterInformation): express.RequestHandler {
@@ -397,14 +397,14 @@ export class Giuseppe {
397397

398398
let result = routeInfo.route.function.apply(ctrlInstance, paramValues);
399399

400-
if (params.some(p => p.canHandleResponse)) {
401-
return;
402-
}
403-
404400
if (result instanceof Promise) {
405401
result = await result;
406402
}
407403

404+
if (params.some(p => p.canHandleResponse)) {
405+
return;
406+
}
407+
408408
returnTypeHandler.handleValue(result, res);
409409
} catch (e) {
410410
meta.errorHandler().handleError(ctrlInstance, req, res, e);
@@ -415,11 +415,11 @@ export class Giuseppe {
415415
/**
416416
* Check if a given controller, the routes of the controller, the modificators and parameters of the route are
417417
* registered within a plugin in giuseppe. If not, throw an exception.
418-
*
418+
*
419419
* @protected
420-
* @throws {DefinitionNotRegisteredError}
421-
* @param {ControllerDefinition} controller
422-
* @returns {boolean}
420+
* @throws {DefinitionNotRegisteredError}
421+
* @param {ControllerDefinition} controller
422+
* @returns {boolean}
423423
* @memberof Giuseppe
424424
*/
425425
protected checkPluginRegistration(controller: ControllerDefinition): boolean {

0 commit comments

Comments
 (0)