diff --git a/templates/index.html.ep b/templates/index.html.ep index 27de8d1..242f541 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -1,100 +1,6 @@ - - - - Urupam - URL Shortener - - - - - +% layout 'default'; +% stash title => 'Urupam - URL Shortener'; +

Urupam

@@ -132,13 +38,21 @@ body: JSON.stringify({ url: url }) }); - const data = await response.json(); + const contentType = response.headers.get('content-type') || ''; + let data = {}; + if (contentType.includes('application/json')) { + data = await response.json(); + } else { + const text = await response.text(); + data = { error: text || 'Unexpected response' }; + } if (response.ok && data.success) { showSuccess(data.short_url, data.original_url); urlInput.value = ''; } else { - showError(data.error || 'An error occurred'); + const message = data.error || `Request failed (${response.status})`; + showError(message); } } catch (error) { showError('Network error: ' + error.message); @@ -176,5 +90,4 @@ return div.innerHTML; } - - +