fixed sending error twice when another middleware already sent the headers