I'm using "reqwest" to make rest call to service. I'm interested in the error that occur while making a call. Here is my simple exmple
<!doctype html>
<html>
<body>
<script src="node_modules/es6-promise/dist/es6-promise.js"></script>
<script src="node_modules/reqwest/reqwest.js"></script>
<script src="src/js/test.js"></script>
</body>
</html>
Here is my test.js
reqwest({
url: "www.google.com"
, type: 'json'
, method: 'post'
, contentType: 'application/json'
, headers: {
'X-My-Custom-Header': 'SomethingImportant'
}
}).then((res)=> {
alert(res);
}, (err)=> {
alert(err);
});
The following error is printed on my console.
XMLHttpRequest cannot load http://www.google.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 405.
I want to capture this information, but the call back function on failure does not capture this information in err param. It is empty XMLHTTPRequest. I am sure it does not have any other parameters. Never the less the request cannot be empty. What am I doing wrong.