Unify YouTube Error Handling - #6146
Open
michelinewu wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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→TStreamErrorTypemapping, with a unified formatter/mapper for rejected requests. - Extended
StreamError/IRejectedRequestto preservereasonand 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; | ||
| } |
BundleMonFiles updated (1)
Unchanged files (3)
Total files change +37.65KB +0.24% Final result: ✅ View report in BundleMon website ➡️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_FAILEDtype with no way to tell "create broadcast failed" from "fetch channel failed."StreamErroralso blankedthis.urlentirely for YouTube errors, which prevented identifying which endpoint had actually failed either.Fixes
youtube/api.tsandEYoutubeErrorReasonDocuments every YouTube reason code.updateBroadcastAmonetizationDetailsModificationNotAllowedrejection now retries once withmonetizationDetailsdropped 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.jsonPerformance 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.