mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-24 18:41:57 +01:00
🐛 Fix crash with undefined id in interaction
This commit is contained in:
parent
14cd54fd7d
commit
50a9b15f09
@ -1,6 +1,3 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { JellyfinService } from './jellyfin.service';
|
||||
|
||||
import {
|
||||
BaseItemKind,
|
||||
RemoteImageResult,
|
||||
@ -10,12 +7,17 @@ import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api';
|
||||
import { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
||||
import { getRemoteImageApi } from '@jellyfin/sdk/lib/utils/api/remote-image-api';
|
||||
import { getSearchApi } from '@jellyfin/sdk/lib/utils/api/search-api';
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Logger } from '@nestjs/common/services';
|
||||
|
||||
import {
|
||||
JellyfinAudioPlaylist,
|
||||
JellyfinMusicAlbum,
|
||||
} from '../../models/jellyfinAudioItems';
|
||||
|
||||
import { JellyfinService } from './jellyfin.service';
|
||||
|
||||
@Injectable()
|
||||
export class JellyfinSearchService {
|
||||
private readonly logger = new Logger(JellyfinSearchService.name);
|
||||
@ -110,23 +112,31 @@ export class JellyfinSearchService {
|
||||
const api = this.jellyfinService.getApi();
|
||||
const remoteImageApi = getRemoteImageApi(api);
|
||||
|
||||
const axiosReponse = await remoteImageApi.getRemoteImages({
|
||||
itemId: id,
|
||||
includeAllLanguages: true,
|
||||
limit: 20,
|
||||
});
|
||||
try {
|
||||
const axiosReponse = await remoteImageApi.getRemoteImages({
|
||||
itemId: id,
|
||||
includeAllLanguages: true,
|
||||
limit: 20,
|
||||
});
|
||||
|
||||
if (axiosReponse.status !== 200) {
|
||||
this.logger.warn(
|
||||
`Failed to retrieve remote images. Response has status ${axiosReponse.status}`,
|
||||
);
|
||||
if (axiosReponse.status !== 200) {
|
||||
this.logger.warn(
|
||||
`Failed to retrieve remote images. Response has status ${axiosReponse.status}`,
|
||||
);
|
||||
return {
|
||||
Images: [],
|
||||
Providers: [],
|
||||
TotalRecordCount: 0,
|
||||
};
|
||||
}
|
||||
return axiosReponse.data;
|
||||
} catch (err) {
|
||||
this.logger.error(`Failed to retrieve remote images: ${err}`);
|
||||
return {
|
||||
Images: [],
|
||||
Providers: [],
|
||||
TotalRecordCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
return axiosReponse.data;
|
||||
}
|
||||
}
|
||||
|
@ -198,6 +198,13 @@ export class PlayItemCommand {
|
||||
const type = valueParts[0];
|
||||
const id = valueParts[1];
|
||||
|
||||
if (!id) {
|
||||
this.logger.warn(
|
||||
`Failed because ID could not be extracted from interaction`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
`Searching for the content using the values [${interaction.values.join(
|
||||
', ',
|
||||
|
Loading…
Reference in New Issue
Block a user