mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Simplify image download error handling
This commit is contained in:
+3
-13
@@ -172,19 +172,9 @@ async function loadImageFilePromise(imageUrl) {
|
|||||||
requestConfig.httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
requestConfig.httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffer;
|
const response = await axios(requestConfig);
|
||||||
try {
|
const buffer = Buffer.from(response.data, 'binary');
|
||||||
const response = await axios(requestConfig);
|
|
||||||
buffer = Buffer.from(response.data, 'binary');
|
|
||||||
} catch (ex) {
|
|
||||||
if (ex.response) {
|
|
||||||
// request was made, but server responded with an error status code
|
|
||||||
throw new Error('StatusCodeError: ' + ex.response.status);
|
|
||||||
} else {
|
|
||||||
// something else went wrong, rethrow
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user