Open markstos opened 9 years ago
Yes, its basically the same idea: using typecheckable/streamlined js errors for the very common use case of HTTP errors.
I will try and document it asap, but you can already see its usage for example here https://github.com/elierotenberg/nexus-uplink-simple-server/blob/master/src/UplinkSimpleServer.js#L155.
Feel free to PR :)
I'm noting this the is other half of the code example: Shown how an exception is caught in a web framework middleware and converted to an HTTP response:
if (err instanceof HTTPExceptions.HTTPError) {
return HTTPExceptions.forward(res, err);
}
And here are direct examples of what using the module looks like:
throw new HTTPExceptions.BadRequest(`Missing required field: 'params'.`);
throw new HTTPExceptions.NotFound(req.path);
I think this is clean way to break the control flow in a promise chain. It's also way way for the "Model" code to communicate with a web framework, without requiring passing around a "request" object or some other hard dependency on a web framework.
Hello,
Is this like HTTP::Exception from Perl? It'd be great if the README could be updated with documentation of what methods are contained in here and what an example usage looks like.