mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-11 19:46:16 -08:00
refactor: improve error handling
This commit is contained in:
2 files changed
+40
-19
No files matched your search
@@ -16,20 +16,27 @@ const db = new Nedb<Playlist>({
|
||||
|
||||
export class Api {
|
||||
constructor() {
|
||||
ipcMain.on('parse-playlist-by-url', (event, args) => {
|
||||
axios.get(args.url).then((result) => {
|
||||
const array = result.data.split('\n');
|
||||
const parsedPlaylist = this.parsePlaylist(array);
|
||||
const playlistObject = this.createPlaylistObject(
|
||||
args.title,
|
||||
parsedPlaylist,
|
||||
args.url
|
||||
);
|
||||
this.insertToDb(playlistObject);
|
||||
event.sender.send('parse-response', {
|
||||
payload: playlistObject,
|
||||
ipcMain.on('parse-playlist-by-url', async (event, args) => {
|
||||
try {
|
||||
await axios.get(args.url).then((result) => {
|
||||
const array = result.data.split('\n');
|
||||
const parsedPlaylist = this.parsePlaylist(array);
|
||||
const playlistObject = this.createPlaylistObject(
|
||||
args.title,
|
||||
parsedPlaylist,
|
||||
args.url
|
||||
);
|
||||
this.insertToDb(playlistObject);
|
||||
event.sender.send('parse-response', {
|
||||
payload: playlistObject,
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
event.sender.send('error', {
|
||||
message: err.response.statusText,
|
||||
status: err.response.status,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('parse-playlist', (event, args) => {
|
||||
|
||||
@@ -42,6 +42,13 @@ export class HomeComponent {
|
||||
this.electronService.ipcRenderer.send('playlists-all');
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'error',
|
||||
execute: (response: { message: string; status: number }) =>
|
||||
this.showNotification(
|
||||
`Error: ${response.status} ${response.message}. Please check the entered playlist URL again.`
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -84,12 +91,8 @@ export class HomeComponent {
|
||||
* @param fileName name of the uploaded file
|
||||
*/
|
||||
rejectFile(fileName: string): void {
|
||||
this.snackBar.open(
|
||||
`File was rejected, unsupported file format (${fileName}).`,
|
||||
null,
|
||||
{
|
||||
duration: 2000,
|
||||
}
|
||||
this.showNotification(
|
||||
`File was rejected, unsupported file format (${fileName}).`
|
||||
);
|
||||
this.isLoading = false;
|
||||
}
|
||||
@@ -176,4 +179,15 @@ export class HomeComponent {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows snack bar notification with a given message
|
||||
* @param message message to show
|
||||
* @param duration visibility duration of the snackbar
|
||||
*/
|
||||
showNotification(message: string, duration = 2000): void {
|
||||
this.snackBar.open(message, null, {
|
||||
duration,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user