Skip to content

Commit

Permalink
fix: use separate title + message in labels
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Dec 4, 2024
1 parent ce81a83 commit 2fc9a4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
20 changes: 16 additions & 4 deletions src/js/labels/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ export type LabelOptions = { seekOffset?: number; playbackRate?: number };
// Setting a code explicitely to null makes the error not show up in the UI.
export const errors = {
1: null,
2: 'Network Error: A network error caused the media download to fail.',
3: 'Decode Error: A media error caused playback to be aborted. The media could be corrupt or your browser does not support this format.',
4: 'Source Not Supported: An unsupported error occurred. The server or network failed, or your browser does not support this format.',
5: 'Encryption Error: The media is encrypted and there are no keys to decrypt it.',
2: {
title: 'Network Error',
message: 'A network error caused the media download to fail.',
},
3: {
title: 'Decode Error',
message: 'A media error caused playback to be aborted. The media could be corrupt or your browser does not support this format.',
},
4: {
title: 'Source Not Supported',
message: 'An unsupported error occurred. The server or network failed, or your browser does not support this format.',
},
5: {
title: 'Encryption Error',
message: 'The media is encrypted and there are no keys to decrypt it.',
},
};

export const tooltipLabels = {
Expand Down
16 changes: 6 additions & 10 deletions src/js/media-error-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@ function shouldOpenErrorDialog(errorCode?: number) {
}

function formatErrorMessage(error: MediaErrorLike) {
const message: string = errors[error.code] ?? error.message ?? '';
const parts = message.split(':', 2);

if (parts.length === 2) {
return /*html*/ `
<h3>${parts[0]}</h3>
<p>${parts[1]}</p>
`;
}
return /*html*/ `<p>${message}</p> `;
const title: string = errors[error.code]?.title ?? '';
const message: string = errors[error.code]?.message ?? error.message ?? '';
let html = '';
if (title) html += `<h3>${title}</h3>`;
if (message) html += `<p>${message}</p>`;
return html;
}

const observedAttributes: string[] = [
Expand Down

0 comments on commit 2fc9a4d

Please sign in to comment.