diff --git a/index.d.ts b/index.d.ts index acfd279..26ef0a5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -89,6 +89,12 @@ declare namespace electronDl { */ readonly onCompleted?: (file: File) => void; + /** + Optional callback that receives an error title and an error message. It is called every time when download state is "interrupted". + If callback is not provided error will be shown in Electron error dialog. + */ + readonly onError?: (errorTitle: string, errorMessage: string) => void; + /** Reveal the downloaded file in the system file manager, and if possible, select the file. diff --git a/index.js b/index.js index 58c1df2..46b47c6 100644 --- a/index.js +++ b/index.js @@ -195,7 +195,11 @@ module.exports = (options = {}) => { registerListener(session, options, (error, _) => { if (error && !(error instanceof CancelError)) { const errorTitle = options.errorTitle || 'Download Error'; - dialog.showErrorBox(errorTitle, error.message); + if ('onError' in options && typeof options.onError === 'function') { + options.onError(errorTitle, error.message); + } else { + dialog.showErrorBox(errorTitle, error.message); + } } }); }); diff --git a/readme.md b/readme.md index ab5a420..26b5710 100644 --- a/readme.md +++ b/readme.md @@ -191,6 +191,14 @@ Optional callback that receives an object with information about an item that ha } ``` +#### onError + +Type: `Function` + +Optional callback that receives an error title and an error message. It is called every time when download state is "interrupted". +If callback is not provided error will be shown in Electron error dialog. +(*is applied only in default exported function, not for usage inside 'download' function) + #### openFolderWhenDone Type: `boolean`\