electron-cgi icon indicating copy to clipboard operation
electron-cgi copied to clipboard

Make sure a received request is handled

Open wbzhong-hello opened this issue 4 years ago • 2 comments

inputStreamParser.onRequest(request => { const requestType = request.type; requestHandlersQueue.filter(rh => rh.type === requestType).forEach(handlerContainer => { const requestHandler = handlerContainer.onRequest; const resultArgs = requestHandler(request.args) sendResponse(request.id, resultArgs); }); });

What if requestHandlersQueue.filter returns an empty array, maybe because the programmer forgot to subscribe it or a typo in the requestType.

It is better to check the outcome of requestHandlersQueue.filter, and throw an error when it is empty.

wbzhong-hello avatar Aug 24 '20 16:08 wbzhong-hello

If not an error than at least a warning. I think in the .NET side of things there's an error in the same scenario. Whatever it is it should be consistent

ruidfigueiredo avatar Aug 24 '20 22:08 ruidfigueiredo

Thanks for the reply. It seems that the .NET side will throw a NoRequestHandlerFoundException if there is no matching handler.

wbzhong-hello avatar Aug 25 '20 11:08 wbzhong-hello