Skip to content

Unify YouTube Error Handling - #6146

Open
michelinewu wants to merge 5 commits into
masterfrom
mw_yt_err
Open

Unify YouTube Error Handling#6146
michelinewu wants to merge 5 commits into
masterfrom
mw_yt_err

Conversation

@michelinewu

Copy link
Copy Markdown
Contributor

Refactor YouTube API Error Handling

Issues

YouTube errors were classified inconsistently depending which call site failed, and almost everything collapsed into the generic PLATFORM_REQUEST_FAILED type with no way to tell "create broadcast failed" from "fetch channel failed." StreamError also blanked this.url entirely for YouTube errors, which prevented identifying which endpoint had actually failed either.

Fixes

  • Added youtube/api.ts and EYoutubeErrorReason Documents every YouTube reason code.
  • Unified error handling for YouTube through a single handler.
  • Added a retry in updateBroadcast A monetizationDetailsModificationNotAllowed rejection now retries once with monetizationDetails dropped instead of failing the whole update.

Files changed: app/services/streaming/stream-error.ts, app/services/platforms/base-platform.ts, app/services/platforms/index.ts, app/services/platforms/patreon.ts, app/services/platforms/youtube.ts, app/services/platforms/youtube/api.ts (new), app/services/platforms/youtube/errors.ts (new), app/services/platforms/youtube/index.ts (new), app/i18n/en-US/app.json, app/i18n/en-US/youtube.json

Performance Implications

None for success. On failure, errors now pass through one extra layer of function calls instead of inline branching, which is negligible next to the network round-trip that produced the error.

Copilot AI lite review requested due to automatic review settings August 28, 2026 23:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Streamlabs Desktop’s YouTube platform integration to classify YouTube API failures by endpoint/reason (instead of collapsing into a generic platform error), improve diagnostics (retain sanitized URL + add machine-readable reason), and introduce a targeted retry for a known YouTube monetization write rejection.

Changes:

  • Added centralized YouTube error taxonomy (EYoutubeErrorReason) and endpoint→TStreamErrorType mapping, with a unified formatter/mapper for rejected requests.
  • Extended StreamError/IRejectedRequest to preserve reason and retain YouTube URLs with query params stripped (instead of blanking the URL).
  • Updated YouTube/Patreon platform services to route failures through shared platform error throwing and added a monetization-details retry path in updateBroadcast.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/services/streaming/stream-error.ts Adds YouTube-specific TStreamErrorTypes, adds reason field, and sanitizes YouTube URLs by stripping query params.
app/services/platforms/base-platform.ts Introduces throwPlatformError helper and updates fallback “unknown platform” messaging via i18n.
app/services/platforms/index.ts Adds IPlatformErrorCallbackProps and updates platform service error hook shape.
app/services/platforms/patreon.ts Switches Patreon error handling to use throwPlatformError.
app/services/platforms/youtube.ts Refactors request error handling through a unified YouTube error builder and adds an updateBroadcast retry path.
app/services/platforms/youtube/api.ts New: documents YouTube reason codes and maps endpoints to StreamError types and UI labels.
app/services/platforms/youtube/errors.ts New: centralizes YouTube error type detection + details/statusText formatting + rejected-request shaping.
app/services/platforms/youtube/index.ts New: re-exports YouTube platform submodules.
app/i18n/en-US/app.json Adds a translated fallback message for unknown platform errors.
app/i18n/en-US/youtube.json Adds translation keys for reason labels and newly introduced YouTube error messages/actions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +163 to +165
if (e instanceof StreamError) {
throwStreamError(e.type, e, e.message);
}
Comment on lines +1047 to +1070
} catch (e: unknown) {
this.createPlatformError(
e,
'Error updating broadcast',
'PLATFORM_REQUEST_FAILED',
async () => {
// YouTube reports a broadcast as ads-eligible via eligibleForAdsMonetization and
// then refuses the write if the channel is outside the Partner Program, so the
// flag cannot be trusted as permission. Ad settings are not worth blocking go
// live over — drop them and send the rest.
const isMonetizationRefused =
e instanceof StreamError && e.reason === 'monetizationDetailsModificationNotAllowed';
if (!isMonetizationRefused || !body.monetizationDetails) throw e;

delete body.monetizationDetails;
const retryFields = fields.filter(field => field !== 'monetizationDetails');
broadcast = await this.requestYoutube<IYoutubeLiveBroadcast>({
body: JSON.stringify(body),
method: 'PUT',
url: `${this.apiBase}/liveBroadcasts?part=${retryFields.join(',')}&id=${id}`,
});
},
);
}
Comment on lines +368 to +372
// If a function is provided, skip the default handling
if (fn) {
fn({ e, reqInfo, errorType: reqErrorType });
return;
}
@bundlemon

bundlemon Bot commented Aug 28, 2026

Copy link
Copy Markdown

BundleMon

Files updated (1)
Status Path Size Limits
renderer.(hash).js
10.56MB (+37.65KB +0.35%) -
Unchanged files (3)
Status Path Size Limits
vendors~renderer.(hash).js
4.67MB -
updater.js
115.29KB -
guest-api.js
40.23KB -

Total files change +37.65KB +0.24%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@michelinewu michelinewu added bug needs QA requires QA testing on the branch before merging labels Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug needs QA requires QA testing on the branch before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants