Skip to content

Commit

Permalink
better errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed May 2, 2024
1 parent 83f19c9 commit bd626af
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
40 changes: 30 additions & 10 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ def ex_test():
url = f"https://foo.{app.config['base_url']}/"
data = cloudapp_fetch(session, url, 7, 'info', {"foo": True})
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_test2')
def ex_test2():
Expand All @@ -222,8 +224,10 @@ def ex_test2():
url = f"https://bar.{app.config['base_url']}/"
data = cloudapp_fetch(session, url, 7, 'info', {"bar": True})
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")


@app.route('/_lb1')
Expand All @@ -236,8 +240,10 @@ def lb_aws():
url = f"https://{ns}.{app.config['base_url']}"
data = cloudapp_fetch(session, url, 7, 'env', 'AWS')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_lb2')
def lb_azure():
Expand Down Expand Up @@ -276,8 +282,10 @@ def route1():
"azure": azure_data
}
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_route2')
def route2():
Expand All @@ -298,8 +306,10 @@ def route2():
"azure": azure_data
}
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_manip1')
def manip1():
Expand All @@ -312,8 +322,10 @@ def manip1():
url = f"https://{ns}.{base_url}/aws/raw"
r_data = cloudapp_fetch(session, url, 5, 'info', {"method": "GET", "path": "/raw"})
return jsonify(status='success', data=r_data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_manip2')
def manip2():
Expand All @@ -327,8 +339,10 @@ def manip2():
t_headers = { "x-mcn-namespace": ns, "x-mcn-src-site": app.config["ce_info"]["site_name"]}
r_data = cloudapp_req_headers(session, url, 7, t_headers)
return jsonify(status='success', data=r_data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_manip3')
def manip3():
Expand All @@ -349,8 +363,10 @@ def manip3():
"azure": azure_data
}
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_port1')
def port1():
Expand All @@ -362,8 +378,10 @@ def port1():
url = f"https://{ns}.{app.config['base_url']}/"
data = cloudapp_fetch(session, url, 7, 'info', {"method": "GET", "path": "/"})
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")

@app.route('/_port2', methods=['POST'])
def port2():
Expand All @@ -375,8 +393,10 @@ def port2():
url = f"https://{eph_ns}.{app.config['base_url']}/"
data = cloudapp_fetch(session, url, 7, 'info', {"method": "GET", "path": "/"})
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
except (LabException, ValueError) as e:
return jsonify(status='fail', error=str(e))
except requests.RequestException:
return jsonify(status='fail', error="Connection/Request Error")


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion labapp/app/markdown/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Host: eph-ns.mcn-lab.f5demos.com
```

<div class="alert alert-secondary" role="alert">
This test will make up to 5 requests.
<strong>This test will make up to 5 requests.</strong>
</div>

<div class="left-aligned-button-container">
Expand Down
2 changes: 1 addition & 1 deletion labapp/app/markdown/manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Host: eph-ns.mcn-lab.f5demos.com
```

<div class="alert alert-secondary" role="alert">
This test evaluates response headers.
<strong>This test evaluates response headers.</strong>
</div>

<div class="left-aligned-button-container">
Expand Down

0 comments on commit bd626af

Please sign in to comment.