Skip to content

Commit

Permalink
fix(profiles): catch server errors and send to client
Browse files Browse the repository at this point in the history
  • Loading branch information
ankarhem committed Feb 6, 2021
1 parent 57e6fce commit 8b2c7d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
3 changes: 1 addition & 2 deletions server/api/sonarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,8 @@ class SonarrAPI extends ExternalAPI {
message: e.message,
}
);
return [];

// throw new Error('Failed to get language profiles');
throw new Error('Failed to get language profiles');
}
}

Expand Down
64 changes: 34 additions & 30 deletions server/routes/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,40 @@ serviceRoutes.get<{ sonarrId: string }>(
}:${sonarrSettings.port}${sonarrSettings.baseUrl ?? ''}/api`,
});

const profiles = await sonarr.getProfiles();
const rootFolders = await sonarr.getRootFolders();
const languageProfiles = await sonarr.getLanguageProfiles();

return res.status(200).json({
server: {
id: sonarrSettings.id,
name: sonarrSettings.name,
is4k: sonarrSettings.is4k,
isDefault: sonarrSettings.isDefault,
activeDirectory: sonarrSettings.activeDirectory,
activeProfileId: sonarrSettings.activeProfileId,
activeAnimeProfileId: sonarrSettings.activeAnimeProfileId,
activeAnimeDirectory: sonarrSettings.activeAnimeDirectory,
activeLanguageProfileId: sonarrSettings.activeLanguageProfileId,
activeAnimeLanguageProfileId:
sonarrSettings.activeAnimeLanguageProfileId,
},
profiles: profiles.map((profile) => ({
id: profile.id,
name: profile.name,
})),
rootFolders: rootFolders.map((folder) => ({
id: folder.id,
freeSpace: folder.freeSpace,
path: folder.path,
totalSpace: folder.totalSpace,
})),
languageProfiles: languageProfiles,
} as ServiceCommonServerWithDetails);
try {
const profiles = await sonarr.getProfiles();
const rootFolders = await sonarr.getRootFolders();
const languageProfiles = await sonarr.getLanguageProfiles();

return res.status(200).json({
server: {
id: sonarrSettings.id,
name: sonarrSettings.name,
is4k: sonarrSettings.is4k,
isDefault: sonarrSettings.isDefault,
activeDirectory: sonarrSettings.activeDirectory,
activeProfileId: sonarrSettings.activeProfileId,
activeAnimeProfileId: sonarrSettings.activeAnimeProfileId,
activeAnimeDirectory: sonarrSettings.activeAnimeDirectory,
activeLanguageProfileId: sonarrSettings.activeLanguageProfileId,
activeAnimeLanguageProfileId:
sonarrSettings.activeAnimeLanguageProfileId,
},
profiles: profiles.map((profile) => ({
id: profile.id,
name: profile.name,
})),
rootFolders: rootFolders.map((folder) => ({
id: folder.id,
freeSpace: folder.freeSpace,
path: folder.path,
totalSpace: folder.totalSpace,
})),
languageProfiles: languageProfiles,
} as ServiceCommonServerWithDetails);
} catch (e) {
next({ status: 500, message: e.message });
}
}
);

Expand Down

0 comments on commit 8b2c7d0

Please sign in to comment.