Skip to content

Commit

Permalink
feat(error): Add validation error classes for YouTube ID and URL (#91)
Browse files Browse the repository at this point in the history
- Introduced new error classes for more specific validation error handling:
  - `IDValidationError`: Represents errors for invalid YouTube video IDs during validation.
  - `URLValidationError`: Represents errors for invalid YouTube video URLs during validation.
  - `UnknownYouTubeDomainError`: Represents errors due to invalid or unknown YouTube domains.

- Updated the `error` module to export the new error classes.

These additions provide better error handling and clarity for validation-related operations.

Authored-by: Ryuu Mitsuki <[email protected]>
  • Loading branch information
mitsuki31 authored Jan 13, 2025
1 parent 38c166a commit 3ea5750
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@ const { isPlainObject } = require('./utils/type-utils');
*/
class IDExtractorError extends Error {}

/**
* @classdesc Represents an error that occurred when given
* YouTube video ID is invalid during validation.
*
* @extends Error
* @global
* @since 2.0.0
*/
class IDValidationError extends Error {}

/**
* @classdesc Represents an error that occurred when given
* YouTube video URL is invalid during validation.
*
* @extends Error
* @global
* @since 2.0.0
*/
class URLValidationError extends Error {}

/**
* @classdesc Represents an error that occurred due to invalid or unknown YouTube domain.
*
* @extends Error
* @global
* @since 2.0.0
*/
class UnknownYouTubeDomainError extends Error {}

/**
* @classdesc A class represents the error that occurred due to defining an unknown
* option in the configuration object and may throw during configuration validation.
Expand Down Expand Up @@ -102,6 +131,9 @@ class GlobalConfigParserError extends Error {

module.exports = {
IDExtractorError,
IDValidationError,
URLValidationError,
UnknownYouTubeDomainError,
UnknownOptionError,
InvalidTypeError,
GlobalConfigParserError
Expand Down

0 comments on commit 3ea5750

Please sign in to comment.