diff options
author | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2019-10-24 15:10:16 -0400 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2019-10-29 13:36:55 -0400 |
commit | 1ed8ad1cd716531a0ab573b61599a7baf8a96a9a (patch) | |
tree | ad7618372a769eca1b75e41363a8ed92d3ee21cd /src | |
parent | 1aa69c2a56fe2ad46dfdf10061b9726c18f0e8d8 (diff) | |
download | liza-1ed8ad1cd716531a0ab573b61599a7baf8a96a9a.tar.gz liza-1ed8ad1cd716531a0ab573b61599a7baf8a96a9a.tar.bz2 liza-1ed8ad1cd716531a0ab573b61599a7baf8a96a9a.zip |
RatingService: Return promise
This only replaces the callbacks at the highest level and starts to move
toward proper error handling. The private methods do not yet properly
propagate errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/server/daemon/controller.js | 8 | ||||
-rw-r--r-- | src/server/service/RatingService.ts | 32 |
2 files changed, 18 insertions, 22 deletions
diff --git a/src/server/daemon/controller.js b/src/server/daemon/controller.js index c027e4e..0f9cfa3 100644 --- a/src/server/daemon/controller.js +++ b/src/server/daemon/controller.js @@ -536,11 +536,9 @@ function doRoute( program, request, data, resolve, reject ) { var response = UserResponse( request ); - rating_service.request( request, response, quote, alias, function() - { - // we're done; free the lock - free(); - } ); + rating_service.request( request, response, quote, alias ) + .catch( () => {} ) + .then( () => free() ); } ); }, true ); } diff --git a/src/server/service/RatingService.ts b/src/server/service/RatingService.ts index e811075..9338758 100644 --- a/src/server/service/RatingService.ts +++ b/src/server/service/RatingService.ts @@ -78,24 +78,22 @@ export class RatingService /** * Sends rates to the client * - * Note that the continuation will be called after all data saving is + * Note that the promise will be resolved after all data saving is * complete; the request will be sent back to the client before then. * * @param request - user request to satisfy * @param _response - pending response * @param quote - quote to export * @param cmd - applicable of command request - * @param callback - continuation after saving is complete * - * @return Server self to allow for method chaining + * @return result promise */ request( request: UserRequest, _response: UserResponse, quote: ServerSideQuote, cmd: string, - callback: RequestCallback - ) + ): Promise<void> { // cmd represents a request for a single rater if ( !cmd && this._isQuoteValid( quote ) ) @@ -105,23 +103,23 @@ export class RatingService data: {}, }, [] ); - callback(); - return this; + return Promise.resolve(); } var program = quote.getProgram(); - try - { - this._performRating( request, program, quote, cmd, callback ); - } - catch ( err ) + return new Promise( ( resolve, reject ) => { - this._sendRatingError( request, quote, program, err ); - callback(); - } - - return this; + try + { + this._performRating( request, program, quote, cmd, resolve ); + } + catch ( err ) + { + this._sendRatingError( request, quote, program, err ); + reject( err ); + } + } ); } |