From 1c0f89f4cadba4957e95fc80b25b1b8b6dd1a3b3 Mon Sep 17 00:00:00 2001 From: sterni Date: Mon, 5 Apr 2021 01:53:21 +0200 Subject: feat(web/bubblegum): report some errors to the user via HTTP We can actually catch some errors that may be generated in bubblegum applications where we can report them to the user in a way that doesn't require curl -vv: * Type errors in the status argument: By removing yants completely we not only (presumably) gain some performance, but also the ability to return an internal server error on an unexpected type instead of throwing. * User generated evaluation errors: by using builtins.tryEval we can catch throws and asserts the user inserted when generating the body and report to the user that something went wrong. To do: also support for the headers. Change-Id: I8363b9825c6c730e624eb8016a5482d63cbc1890 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2849 Tested-by: BuildkiteCI Reviewed-by: sterni --- web/bubblegum/examples/hello.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'web/bubblegum/examples/hello.nix') diff --git a/web/bubblegum/examples/hello.nix b/web/bubblegum/examples/hello.nix index 881426bd12..f6706eb217 100644 --- a/web/bubblegum/examples/hello.nix +++ b/web/bubblegum/examples/hello.nix @@ -33,6 +33,18 @@ let No coffee, I'm afraid ''; }; + "/type-error" = { + status = 666; + title = "bad usage"; + content = '' + Never gonna see this. + ''; + }; + "/eval-error" = { + status = "OK"; + title = "evaluation error"; + content = builtins.throw "lol"; + }; }; notFound = { -- cgit 1.4.1