Fix coordinate parsing to handle DMS format and prevent stack traces
- Add parse_coordinate() function to handle both decimal degrees and DMS format - Replace direct float() conversion with robust coordinate parsing - Add proper validation for latitude/longitude ranges - Create user-friendly error page instead of showing stack traces - Support formats like "56°5'58.56"N" and "3°22'33.71"W" - Update both /detail and / routes with improved error handling Fixes #29: Don't return stack trace when lat/lon are not integers
This commit is contained in:
parent
72afb4c286
commit
7235df4cad
2 changed files with 113 additions and 8 deletions
40
templates/coordinate_error.html
Normal file
40
templates/coordinate_error.html
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Geocode to Commons: coordinate error{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div class="m-3">
|
||||
<h1>Geocode coordinates to Commons Category</h1>
|
||||
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ error }}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="coordinates">
|
||||
<strong>Received coordinates:</strong><br>
|
||||
Latitude: {{ lat_str }}<br>
|
||||
Longitude: {{ lon_str }}
|
||||
</div>
|
||||
|
||||
<div class="help-section">
|
||||
<h2 class="help-title">Supported coordinate formats:</h2>
|
||||
|
||||
<div class="examples">
|
||||
<div class="example">Decimal degrees: 56.099600, -3.376031</div>
|
||||
<div class="example">DMS format: 56°5'58.56"N, 3°22'33.71"W</div>
|
||||
<div class="example">Mixed format: 56.099600, 3°22'33.71"W</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
<div>Latitude must be between -90 and 90 degrees.</div>
|
||||
<div>Longitude must be between -180 and 180 degrees.</div>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('index') }}" class="back-link">← Back to Home</a>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue