🐛 Fix crash with undefined id in interaction

This commit is contained in:
Manuel 2023-02-20 22:21:33 +01:00
parent 14cd54fd7d
commit 50a9b15f09
2 changed files with 31 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -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(
', ',