fix 500 middleware errors