Tried to access blob storage API with the following method but getting 403 return without error throw(this happen because I'm trying to access file that does not exist/no permission). How should such error be handled? .catch is already applied while calling the API.
Background.. I'm trying to make mistake by purpose to get a file inside Azure blob storage. I do expect 403 and I wish to handle this properly.
Get method
getReq = async url => {
return new Promise((resolve, reject) => {
axios
.get(url)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
})
});
};
Response received from postman
<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:maskedInfo
Time:maskedInfo</Message>
<AuthenticationErrorDetail>Signature did not match. String to sign used was
/blob/maskedInfo/maskedInfo/maskedInfo.json
ReadOnly
2020-08-04
b
</AuthenticationErrorDetail>
</Error>
Tried:
TryCatch does not catch the issue eitherWhen you call getReq() method, It will return a Promise. So, You should handle the rejection.
getReq("https://somerandomurl.com")
.then(res => {
console.log(res);
})
.catch(err => {
console.error(err);
})
In await style,
try {
const res = await getReq("https://somerandomurl.com");
} catch (err) {
console.error(err);
}