             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())
                 


            next()
        }
	return router
    }
}

        }
    }

    func testErrorHandler() {
        performServerTest(router) {
            self.performRequest("get", path: "/error", callback: {response in 
                XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                do {
                    let body = try response!.readString()
                    XCTAssertEqual(body!,"Caught the error: The operation couldn’t be completed. (RouterTestDomain error 1.)")
                }
                catch{
                    XCTFail("No respose body")
                }
            })
        }
    }

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