ytsearch.js
Reference

Errors & Error Codes

ytsearch.js exposes YtSearchError with a stable code field so applications can handle known failures programmatically.

ts
class YtSearchError extends Error {
  code: YtSearchErrorCode;
  metadata?: Record<string, any>;
}

Error codes

CodeMeaning
INVALID_QUERYThe search query is missing, empty, or not a string.
INVALID_TYPEThe search type is not one of the supported SearchType values.
INVALID_SORTThe requested sort value is not supported.
INVALID_LIMITThe requested page size is outside the function’s accepted range.
PARSE_ERRORThe response could not be parsed into the expected normalized structure.
NO_RESULTSNo matching search results were available.
RATE_LIMITThe upstream service appears to have rate-limited the request.
YOUTUBE_ERRORYouTube returned an error response while processing the request.
YOUTUBE_UNAVAILABLEYouTube was unavailable for the requested operation.
NETWORK_UNAVAILABLEA network request could not be completed.
INVALID_PLAYLISTThe supplied playlist identifier or playlist response was invalid.
NO_PLAYLIST_RESULTSNo videos were found in the requested playlist response.
INVALID_VIDEOThe supplied video identifier or video response was invalid.
UNKNOWNAn error occurred that does not match another documented code.
Treat upstream YouTube parsing and availability as external conditions. Catch YtSearchError around network-facing operations and branch on error.code where recovery behavior matters.