writeErrorResponse