catch 500 in middleware