From f69d2801069850b48c6424b50d0107799d56e2f8 Mon Sep 17 00:00:00 2001 From: Guillaume Pasquet Date: Sun, 20 Feb 2022 09:30:46 +0000 Subject: Handle errors (more) gracefully --- test_api/test_api.py | 19 +++++++++++++++++++ test_api/test_api_404_error.barb | 2 ++ test_api/test_api_500_error.barb | 2 ++ test_api/test_api_get.barb | 1 + test_api/test_api_nonexist_error.barb | 2 ++ test_api/test_api_post.barb | 3 +++ 6 files changed, 29 insertions(+) create mode 100644 test_api/test_api.py create mode 100644 test_api/test_api_404_error.barb create mode 100644 test_api/test_api_500_error.barb create mode 100644 test_api/test_api_get.barb create mode 100644 test_api/test_api_nonexist_error.barb create mode 100644 test_api/test_api_post.barb (limited to 'test_api') diff --git a/test_api/test_api.py b/test_api/test_api.py new file mode 100644 index 0000000..bd8303d --- /dev/null +++ b/test_api/test_api.py @@ -0,0 +1,19 @@ +from bottle import get, post, run, HTTPError + +@get("/") +def get_root(): + return {"status": "OK"} + +@post("/") +def post_root(): + return {"status": "SUCCESS"} + +@get("/errors/404") +def error_404(): + raise HTTPError(404, body={"error": "no exist"}) + +@get("/errors/500") +def error_500(): + raise HTTPError(500, body={"error": "server error"}) + +run(host="localhost", port=8080) diff --git a/test_api/test_api_404_error.barb b/test_api/test_api_404_error.barb new file mode 100644 index 0000000..d2c9809 --- /dev/null +++ b/test_api/test_api_404_error.barb @@ -0,0 +1,2 @@ +#GET^http://localhost:8080/errors/404 + diff --git a/test_api/test_api_500_error.barb b/test_api/test_api_500_error.barb new file mode 100644 index 0000000..1017ab2 --- /dev/null +++ b/test_api/test_api_500_error.barb @@ -0,0 +1,2 @@ +#GET^http://localhost:8080/errors/500 + diff --git a/test_api/test_api_get.barb b/test_api/test_api_get.barb new file mode 100644 index 0000000..6bdf592 --- /dev/null +++ b/test_api/test_api_get.barb @@ -0,0 +1 @@ +#GET^http://localhost:8080/ diff --git a/test_api/test_api_nonexist_error.barb b/test_api/test_api_nonexist_error.barb new file mode 100644 index 0000000..9f95a60 --- /dev/null +++ b/test_api/test_api_nonexist_error.barb @@ -0,0 +1,2 @@ +#GET^http://localhost:60000/ + diff --git a/test_api/test_api_post.barb b/test_api/test_api_post.barb new file mode 100644 index 0000000..2f905b1 --- /dev/null +++ b/test_api/test_api_post.barb @@ -0,0 +1,3 @@ +#POST^http://localhost:8080/ + +{"value": 1234} -- cgit v1.2.3