Nicer error for empty preview spec submission.

This commit is contained in:
Aldo Cortesi 2012-07-25 10:53:29 +12:00
parent 59f408dcf4
commit e7e6a60246
4 changed files with 9 additions and 2 deletions

View File

@ -82,12 +82,17 @@ def _preview(is_request):
template = "response_preview.html"
spec = request.args["spec"]
args = dict(
spec = spec,
section = "main",
syntaxerror = None,
error = None
)
if not spec.strip():
args["error"] = "Can't parse an empty spec."
return render(template, **args)
try:
if is_request:
r = rparse.parse_request(app.config["pathod"].request_settings, spec)

View File

@ -7,7 +7,6 @@
<h2> Error: {{ syntaxerror }} </h2>
<pre>{{ marked }}</pre>
{% elif error %}
<h2> Error </h2>
<p style="color: #ff0000">{{ error }}</p>
{% else %}
<h2>Spec:</h2>

View File

@ -7,7 +7,6 @@
<h2> Error: {{ syntaxerror }} </h2>
<pre>{{ marked }}</pre>
{% elif error %}
<h2> Error </h2>
<p style="color: #ff0000">{{ error }}</p>
{% else %}
<h2>Spec:</h2>

View File

@ -59,3 +59,7 @@ class TestApp(tutils.DaemonTests):
assert r.status_code == 200
assert 'Request' in r.content
r = self.getpath("/request_preview", params=dict(spec=""))
assert r.status_code == 200
assert 'empty spec' in r.content