 
             next()
         }
+
+        router.error { request, response, next in
+            response.setHeader("Content-Type", value: "text/plain; charset=utf-8")
+            do {
+                try response.send("Caught the error: \(response.error!.localizedDescription)").end()
+            }
+            catch {}
+            next()
+        }
+
 	return router
     }
 }

        }
    }

    static func setupRouter() -> Router {
        let router = Router()
        // the same router definition is used for all these test cases

            next()
        }

        // Error handling example
        router.get("/error") { _, response, next in
            response.status(HttpStatusCode.INTERNAL_SERVER_ERROR)
            response.error = NSError(domain: "RouterTestDomain", code: 1, userInfo: [:])
            next()
        }


        router.use("/bodytest", middleware: BodyParser())
                
