mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-11 18:56:14 +09:00
Simplify image download error handling
This commit is contained in:
+2
-12
@@ -172,19 +172,9 @@ async function loadImageFilePromise(imageUrl) {
|
|||||||
requestConfig.httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
requestConfig.httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffer;
|
|
||||||
try {
|
|
||||||
const response = await axios(requestConfig);
|
const response = await axios(requestConfig);
|
||||||
buffer = Buffer.from(response.data, 'binary');
|
const 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