Added 500 error capture

I added 500 status code handling.