Skip to content

Commit

Permalink
Error-Handling im Client
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoegl committed Nov 13, 2011
1 parent 0e9fc9e commit 48a5171
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
Expand Up @@ -45,6 +45,13 @@ private LegacyCustomerRelationsManagement()
public Customer getCustomerByName(String name)
throws LegacyException
{
name = name.trim();

if(name.isEmpty())
{
throw new LegacyException("Can't search for Customer without name (getCustomerByName)");
}

for(Customer customer : customers.values())
{
String fullname = customer.getFirstName() + " " + customer.getMiddleName() + " " + customer.getLastName();
Expand Down
12 changes: 12 additions & 0 deletions webapp/frontend/static/screen.css
Expand Up @@ -52,3 +52,15 @@ th[colspan="2"]
padding-top: 1em;
font-size: 1.2em;
}



div.error
{
margin-top: 3em;
border: thin solid #8B3130;
background-color: #B97F82;
width: 30%;
padding: .5em;
color: #523B51;
}
9 changes: 9 additions & 0 deletions webapp/frontend/templates/base.html
Expand Up @@ -14,6 +14,15 @@ <h1><a href="/">Credit Approval Client</a></h1>
{% block content %}

{% endblock %}

{% if messages %}
{% for message in messages %}
<div{% if message.tags %} class="{{ message.tags }}"{% endif %}>
{{ message }}
</div>
{% endfor %}
{% endif %}

</div>
</body>
</html>
1 change: 1 addition & 0 deletions webapp/frontend/templates/index.html
Expand Up @@ -16,5 +16,6 @@ <h2>Select Customer</h2>
<input type="submit" value="Search" />
</td>
</tr>
</table>
</form>
{% endblock %}
21 changes: 17 additions & 4 deletions webapp/frontend/views.py
Expand Up @@ -2,6 +2,7 @@
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib import messages

from webapp.backend import creditapprovalclient, ratingclient
from webapp.frontend import sessionstore
Expand All @@ -23,9 +24,15 @@ def index(request):
def enter_request(request):

name = request.POST['name']
customer = creditapprovalclient.getCustomerByName(name)
customer = ratingclient.setRating(customer)
sessionstore.set_customer(request, customer)

try:
customer = creditapprovalclient.getCustomerByName(name)
customer = ratingclient.setRating(customer)
sessionstore.set_customer(request, customer)

except Exception as e:
messages.error(request, e)
return HttpResponseRedirect(request.META['HTTP_REFERER'])

return render_to_response('enter-request.html', {
'customer': customer,
Expand Down Expand Up @@ -54,7 +61,13 @@ def show_warrantor(request):

credit_req = sessionstore.get_request(request)

warrantor = creditapprovalclient.getCustomerByName(name)
try:
warrantor = creditapprovalclient.getCustomerByName(name)
except:
messages.error(request, 'Customer with name "{name}" not found'.format(
name=name))
warrantor = None

if warrantor:
warrantor = ratingclient.setRating(warrantor)
credit_req.warrantors.append(warrantor)
Expand Down

0 comments on commit 48a5171

Please sign in to comment.