raise Unauthorized error when response code 401
error message format changed to json
remove unused code