Prevent sending request when 500 status code is received.

I edited the structure of the handling in first commit.

Added flag to prevent sending request when 500 is received. Possible improvement will be a case for other error status code.