display nicer error messages in main app
authorLunar <lunar@anargeek.net>
Mon, 9 Apr 2012 12:16:19 +0000 (14:16 +0200)
committerLunar <lunar@anargeek.net>
Thu, 14 Mar 2013 09:12:10 +0000 (10:12 +0100)
lib/coquelicot/app.rb
views/download_in_progress.haml [new file with mode: 0644]
views/error.haml [new file with mode: 0644]
views/forbidden.haml [new file with mode: 0644]
views/not_found.haml [new file with mode: 0644]

index 62e260e..d9cfa32 100644 (file)
@@ -95,7 +95,21 @@ module Coquelicot
     use Rainbows::MaxBody, 5 * 1024
 
     not_found do
-      'Not found'
+      @uri = env['REQUEST_URI']
+      haml :not_found
+    end
+
+    error 403 do
+      haml :forbidden
+    end
+
+    error 409 do
+      haml :download_in_progress
+    end
+
+    error 500..510 do
+      @error = env['sinatra.error'] || response.body.join
+      haml :error
     end
 
     get '/style.css' do
diff --git a/views/download_in_progress.haml b/views/download_in_progress.haml
new file mode 100644 (file)
index 0000000..a1acf3c
--- /dev/null
@@ -0,0 +1,2 @@
+%h1 Download in progress
+%p The requested file is currently being downloaded by another client.
diff --git a/views/error.haml b/views/error.haml
new file mode 100644 (file)
index 0000000..c9310d7
--- /dev/null
@@ -0,0 +1,2 @@
+%h1 Error
+%p Something bad happened: #{@error}
diff --git a/views/forbidden.haml b/views/forbidden.haml
new file mode 100644 (file)
index 0000000..b10dd2c
--- /dev/null
@@ -0,0 +1,2 @@
+%h1 Forbidden
+%p This password does not allow access to this resource.
diff --git a/views/not_found.haml b/views/not_found.haml
new file mode 100644 (file)
index 0000000..e0631aa
--- /dev/null
@@ -0,0 +1,2 @@
+%h1 Not found
+%p The requested URL #{@uri} was not found on this server.