Fixed error handler middleware