mdneuzerling / lambdr

Run R containers on AWS Lambda
https://lambdr.mdneuzerling.com
Other
131 stars 12 forks source link

Use rlang's error generators to handle invocation and initialisation errors? #8

Open jimjam-slam opened 3 years ago

jimjam-slam commented 3 years ago

I proposed using a replacement for base::stop during endpoint initialisation and invocation so that you can pass HTTP error codes when invoking an endpoint using API Gateway.

Turns out rlang already has helpers for this. It can supply a class using the class argument, so that you can target it with error handlers, and you can supply metadata (like an HTTP code) using the dots.

It's not fundamentally different to what you're already doing, but if you want to shift some of the associated boilerplate to rlang's implementation (and perhaps not have API builders ask "What's stop_api"?), it's there and documented 🎉