Skip to content

Commit

Permalink
fix: handle all entitlement errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Dec 5, 2024
1 parent 2c37f81 commit 428c506
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/services/FavoriteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const schema = array(
object().shape({
mediaid: string(),
}),
).nullable();
);

@injectable()
export default class FavoriteService {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/WatchHistoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const schema = array(
mediaid: string(),
progress: number(),
}),
).nullable();
);

@injectable()
export default class WatchHistoryService {
Expand Down
15 changes: 12 additions & 3 deletions packages/ui-react/src/components/PlayerError/PlayerError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ import styles from './PlayerError.module.scss';

export enum PlayerErrorState {
GEO_BLOCKED = 'GEO_BLOCKED',
UNAUTHORIZED = 'UNAUTHORIZED',
UNKNOWN = 'UNKNOWN',
}

type Props = {
error: keyof typeof PlayerErrorState;
};

const PlayerError: React.FC<Props> = () => {
const PlayerError: React.FC<Props> = ({ error }) => {
const { t } = useTranslation('video');

// t('player_error.geo_blocked.title')
// t('player_error.geo_blocked.description')
// t('player_error.unauthorized.title')
// t('player_error.unauthorized.description')
// t('player_error.unknown.title')
// t('player_error.unknown.description')
return (
<div className={styles.error}>
<h2 className={styles.title}>{t('player_error.geo_blocked_title')}</h2>
<p>{t('player_error.geo_blocked_description')}</p>
<h2 className={styles.title}>{t(`player_error.${error.toLowerCase()}.title`)}</h2>
<p>{t(`player_error.${error.toLowerCase()}.description`)}</p>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ const PlayerContainer: React.FC<Props> = ({

const handlePlaylistItemCallback = usePlaylistItemCallback(liveStartDateTime, liveEndDateTime);

if (error instanceof Error && error.message === 'access blocked') {
return <PlayerError error={PlayerErrorState.GEO_BLOCKED} />;
if (isLoading || isAdsLoading) {
return <LoadingOverlay inline />;
}

if (!playableItem || isLoading || isAdsLoading) {
return <LoadingOverlay inline />;
if (!playableItem || error instanceof Error) {
let playerError = PlayerErrorState.UNKNOWN;

if (error instanceof Error) {
if (error.message.toLowerCase() === 'access blocked') playerError = PlayerErrorState.GEO_BLOCKED;
if (error.message.toLowerCase() === 'unauthorized') playerError = PlayerErrorState.UNAUTHORIZED;
}

return <PlayerError error={playerError} />;
}

return (
Expand Down
14 changes: 12 additions & 2 deletions platforms/web/public/locales/en/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
"favorites_warning": "Maximum amount of favorite videos exceeded. You can only add up to {{maxCount}} favorite videos. Please delete one and repeat the operation.",
"live": "Live",
"player_error": {
"geo_blocked_description": "We apologize, but this content is currently unavailable in your region.",
"geo_blocked_title": "Content unavailable"
"geo_blocked": {
"description": "We apologize, but this content is currently unavailable in your region.",
"title": "Content unavailable"
},
"unauthorized": {
"description": "We apologize, but you are not authorized to watch this content",
"title": "Content unavailable"
},
"unknown": {
"description": "We apologize, but something went wrong while loading the content",
"title": "Content unavailable"
}
},
"season": "season",
"season_number_filter_template": "Season {{seasonNumber}}",
Expand Down
14 changes: 12 additions & 2 deletions platforms/web/public/locales/es/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
"favorites_warning": "Se ha alcanzado el máximo de videos favoritos. Solo puedes agregar hasta {{maxCount}} videos favoritos. Por favor, elimina uno y repite la operación.",
"live": "EN VIVO",
"player_error": {
"geo_blocked_description": "Pedimos disculpas, pero este contenido no está disponible actualmente en tu región.",
"geo_blocked_title": "Contenido no disponible"
"geo_blocked": {
"description": "Pedimos disculpas, pero este contenido no está disponible actualmente en tu región.",
"title": "Contenido no disponible"
},
"unauthorized": {
"description": "Pedimos disculpas, pero no estás autorizado para ver este contenido",
"title": "Contenido no disponible"
},
"unknown": {
"description": "Pedimos disculpas, pero algo salió mal al cargar el contenido",
"title": "Contenido no disponible"
}
},
"season": "temporada",
"season_number_filter_template": "Temporada {{seasonNumber}}",
Expand Down

0 comments on commit 428c506

Please sign in to comment.