1

I use $http to retrieve data from server. In case error happen, all statusCode = -1. I cannot get correct errorCode to handle in client. I don't have permission to update server code.

$http(options).then(function (response) {
                    if (response.status === 200) {
                        resolve(response.data);
                    } else {
                        exceptionHandler(response);
                    }
                }, function (error) {
                    exceptionHandler(error);
                });

console.log is put on exceptionHandler function.

Please help me get correct error code. Many thanks.

Error 404

Error 403

Error 500

1 Answer 1

2

In the responses you have shown, the 404 error is available as error.status but the other two responses were denied access by your browser when it performed the preflight OPTIONS request.

In that case the browser returns a status of -1 to indicate that the request was aborted. There is no HTTP status code for your request because it was never sent. The status 500 shown in the console log is not made available to any javascript code.

You should handle a status of -1 as indicating that no response was received from the server, either because it was never sent (this case), or because it was sent but timed out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.