Intenté acceder a la API de almacenamiento de blobs con el siguiente método, pero obtuve un retorno 403 sin generar un error (esto sucede porque estoy tratando de acceder a un archivo que no existe o no tiene permiso). ¿Cómo se debe manejar tal error? .catch ya se aplicó al llamar a la API.
Antecedentes ... Estoy tratando de cometer un error con el propósito de obtener un archivo dentro del almacenamiento de blobs de Azure. Espero 403 y deseo manejar esto correctamente.
obtener método
getReq = async url => { return new Promise((resolve, reject) => { axios .get(url) .then(function (response) { resolve(response.data); }) .catch(function (error) { reject(error); }) }); };Respuesta recibida del cartero
<?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>Intentó:
TryCatch tampoco detecta el problemaCuando llame al método getReq() , devolverá una Promise . Por lo tanto, debe manejar el rechazo.
getReq("https://somerandomurl.com") .then(res => { console.log(res); }) .catch(err => { console.error(err); })En espera de estilo,
try { const res = await getReq("https://somerandomurl.com"); } catch (err) { console.error(err); }