             case "/p":
                 self.processPlaintext(context: context)
             case "/j":
-                self.processJSON(context: context)
+                do {
+                    try self.processJSON(context: context)
+                } catch {
+                    context.close(promise: nil)
+                }
             default:
-                _ = context.close()
+                context.close(promise: nil)
             }
         case .body:
             break

    static let plainTextResponseLength = plainTextResponse.utf8CodeUnitCount
    static let plainTextResponseLengthString = String(plainTextResponseLength)

    static let jsonResponse = try! JSONEncoder().encode(JSONTestResponse())
    static let jsonResponseLength = try! JSONEncoder().encode(JSONTestResponse()).count
    static let jsonResponseLengthString = String(jsonResponseLength)
}

        context.write(self.wrapOutboundOut(.body(.byteBuffer(self.plaintextBuffer))), promise: nil)
    }

    private func processJSON(context: ChannelHandlerContext) throws {
        let responseHead = self.responseHead(contentType: "application/json", contentLength: Constants.jsonResponseLengthString)
        context.write(self.wrapOutboundOut(.head(responseHead)), promise: nil)
        self.jsonBuffer.clear()
        try self.jsonBuffer.writeBytes(self.jsonEncoder.encode(JSONTestResponse()))
        context.write(self.wrapOutboundOut(.body(.byteBuffer(self.jsonBuffer))), promise: nil)
    }

