File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed
run/markdown-preview/editor Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,15 @@ def index():
35
35
def render_handler ():
36
36
body = request .get_json ()
37
37
if not body :
38
- raise Exception ( " Invalid JSON")
38
+ return "Error rendering markdown: Invalid JSON", 400
39
39
40
40
data = body ["data" ]
41
- parsed_markdown = render .new_request (data )
42
- return parsed_markdown
41
+ try :
42
+ parsed_markdown = render .new_request (data )
43
+ return parsed_markdown , 200
44
+ except Exception as err :
45
+ return f"Error rendering markdown: { err } " , 500
46
+
43
47
# [END run_secure_request_do]
44
48
# [END cloudrun_secure_request_do]
45
49
Original file line number Diff line number Diff line change @@ -40,15 +40,15 @@ def test_render_handler_errors(client):
40
40
r = client .get ("/render" )
41
41
assert r .status_code == 405
42
42
43
- with pytest . raises ( Exception ) as e :
44
- client . post ( "/render" , data = "**markdown**" )
45
- assert "Invalid JSON" in str ( e . value )
43
+ r = client . post ( "/render" , data = "**markdown**" )
44
+ assert r . status_code == 400
45
+ assert "Invalid JSON" in r . data . decode ( )
46
46
47
47
48
48
def test_missing_upstream_url (client ):
49
49
del os .environ ["EDITOR_UPSTREAM_RENDER_URL" ]
50
- with pytest .raises (Exception ) as e :
51
- client .post ("/render" ,
50
+ r = client .post ("/render" ,
52
51
data = json .dumps ({"data" : "**strong text**" }),
53
52
headers = {"Content-Type" : "application/json" })
54
- assert "EDITOR_UPSTREAM_RENDER_URL missing" in str (e .value )
53
+ assert r .status_code == 500
54
+ assert "EDITOR_UPSTREAM_RENDER_URL missing" in r .data .decode ()
Original file line number Diff line number Diff line change @@ -33,8 +33,6 @@ def new_request(data):
33
33
raise Exception ("EDITOR_UPSTREAM_RENDER_URL missing" )
34
34
35
35
req = urllib .request .Request (url , data = data .encode ())
36
-
37
- credentials , project = google .auth .default ()
38
36
auth_req = google .auth .transport .requests .Request ()
39
37
target_audience = url
40
38
You can’t perform that action at this time.
0 commit comments