-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: organize and constantize error codes #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 71feafb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis change standardizes YouTube error handling across the codebase by introducing specific error codes and constant messages, updating type definitions, and removing the old error message mapping utility. Video ID validation is now enforced before attempting to load videos, and error reporting uses explicit codes and messages throughout the player components. Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant YoutubePlayer
participant WebView
participant YouTube API
App->>YoutubePlayer: Set videoId
YoutubePlayer->>YoutubePlayer: validateVideoId(videoId)
alt Valid videoId
YoutubePlayer->>WebView: loadVideo(videoId)
WebView->>YouTube API: Request video
YouTube API-->>WebView: Response / Error
WebView->>YoutubePlayer: Post message (success/error)
alt Error
YoutubePlayer->>App: onError(code, message)
end
else Invalid videoId
YoutubePlayer->>App: onError(1002, 'INVALID_YOUTUBE_VIDEO_ID')
end
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Deploying react-native-youtube-bridge with
|
| Latest commit: |
71feafb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cef69552.react-native-youtube-bridge.pages.dev |
| Branch Preview URL: | https://refactor-error-codes.react-native-youtube-bridge.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
src/utils/youtube.ts (1)
3-14: HoistqualityLabelsto avoid per-call allocation
qualityLabelsis recreated on every invocation ofgetQualityLabel. Since it is static data, move it out of the function (or memoise) so it is initialised once and reused.-import type { PlaybackQuality } from '../types/youtube'; - -export const getQualityLabel = (quality: PlaybackQuality): string => { - const qualityLabels: Record<PlaybackQuality, string> = { +import type { PlaybackQuality } from '../types/youtube'; + +const QUALITY_LABELS: Record<PlaybackQuality, string> = { small: '240p', medium: '360p', large: '480p', hd720: '720p HD', hd1080: '1080p HD', highres: '고해상도', - }; - - return qualityLabels[quality] || quality; -}; +} as const; + +export const getQualityLabel = (quality: PlaybackQuality): string => QUALITY_LABELS[quality] ?? quality;src/YoutubePlayer.tsx (2)
115-118: Reuse centralised error strings rather than hard-coding
'FAILED_TO_PARSE_WEBVIEW_MESSAGE'is already defined inERROR_CODES. Importing and re-using the constant prevents drift between files.-import { safeNumber, validateVideoId } from './utils/validate'; +import { safeNumber, validateVideoId } from './utils/validate'; +import { ERROR_CODES } from './types/youtube'; ... -onError?.({ code: 1000, message: 'FAILED_TO_PARSE_WEBVIEW_MESSAGE' }); +onError?.({ code: 1000, message: ERROR_CODES[1000] });
251-254: Ditto: useERROR_CODES[1001]for consistencySame rationale as above – avoid duplicated literals.
src/YoutubePlayer.web.tsx (2)
147-151: Consistency gap on subsequent invalid IDs
createPlayerRefreports1002for an initial invalid ID, but whenvideoIdchanges (effect 285-294) the component merely skips the update. Consider emitting the same error in that code-path so callers are always notified of invalid input.
232-239: Minor: avoid double lookup
ERROR_CODES[errorCode]is computed twice. Cache the value once for readability & micro-perf.-const errorCode = event.data; - -if (ERROR_CODES[errorCode]) { - onError?.({ - code: errorCode, - message: ERROR_CODES[errorCode], - }); +const errorCode = event.data; +const resolved = ERROR_CODES[errorCode]; + +if (resolved) { + onError?.({ code: errorCode, message: resolved }); return; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/YoutubePlayer.tsx(4 hunks)src/YoutubePlayer.web.tsx(3 hunks)src/types/youtube.ts(1 hunks)src/utils/youtube.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/YoutubePlayer.tsx (1)
src/utils/validate.ts (1)
validateVideoId(1-5)
src/YoutubePlayer.web.tsx (1)
src/types/youtube.ts (1)
ERROR_CODES(99-110)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build-web
- GitHub Check: Cloudflare Pages
Summary by CodeRabbit
Bug Fixes
Refactor
Chores