electron-cgi
electron-cgi copied to clipboard
Make sure a received request is handled
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.
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
Thanks for the reply. It seems that the .NET side will throw a NoRequestHandlerFoundException
if there is no matching handler.