Skip to content

Commit 6e10f93

Browse files
committed
feat: add error types and jsdoc @throws
1 parent 93b651e commit 6e10f93

File tree

1 file changed

+108
-2
lines changed

1 file changed

+108
-2
lines changed

types/defines/stream.d.ts

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
*
1414
* Example usage:
1515
* ```ts
16-
* await env.STREAM.video(id).downloads.create();
16+
* await env.STREAM.video(id).downloads.generate();
1717
*
1818
* const video = env.STREAM.video(id)
1919
* const captions = video.captions.list();
20-
* const videoDetails = video.get()
20+
* const videoDetails = video.details()
2121
* ```
2222
*/
2323
interface StreamBinding {
@@ -31,17 +31,33 @@ interface StreamBinding {
3131
* Uploads a new video from a File.
3232
* @param file The video file to upload.
3333
* @returns The uploaded video details.
34+
* @throws {BadRequestError} if the upload parameter is invalid
35+
* @throws {QuotaReachedError} if the account storage capacity is exceeded
36+
* @throws {MaxFileSizeError} if the file size is too large
37+
* @throws {RateLimitedError} if the server received too many requests
38+
* @throws {InternalError} if an unexpected error occurs
3439
*/
3540
upload(file: File): Promise<StreamVideo>;
3641
/**
3742
* Uploads a new video from a provided URL.
3843
* @param url The URL to upload from.
3944
* @param params Optional upload parameters.
4045
* @returns The uploaded video details.
46+
* @throws {BadRequestError} if the upload parameter is invalid or the URL is invalid
47+
* @throws {QuotaReachedError} if the account storage capacity is exceeded
48+
* @throws {MaxFileSizeError} if the file size is too large
49+
* @throws {RateLimitedError} if the server received too many requests
50+
* @throws {AlreadyUploadedError} if a video was already uploaded to this URL
51+
* @throws {InternalError} if an unexpected error occurs
4152
*/
4253
upload(url: string, params?: StreamUrlUploadParams): Promise<StreamVideo>;
4354
/**
4455
* Creates a direct upload that allows video uploads without an API key.
56+
* @param params Parameters for the direct upload
57+
* @returns The direct upload details.
58+
* @throws {BadRequestError} if the parameters are invalid
59+
* @throws {RateLimitedError} if the server received too many requests
60+
* @throws {InternalError} if an unexpected error occurs
4561
*/
4662
createDirectUpload(
4763
params: StreamDirectUploadCreateParams
@@ -62,22 +78,30 @@ interface StreamVideoHandle {
6278
/**
6379
* Get a full videos details
6480
* @returns The full video details.
81+
* @throws {NotFoundError} if the video is not found
82+
* @throws {InternalError} if an unexpected error occurs
6583
*/
6684
details(): Promise<StreamVideo>;
6785
/**
6886
* Update details for a single video.
6987
* @param params The fields to update for the video.
7088
* @returns The updated video details.
89+
* @throws {NotFoundError} if the video is not found
90+
* @throws {BadRequestError} if the parameters are invalid
91+
* @throws {InternalError} if an unexpected error occurs
7192
*/
7293
update(params: StreamUpdateVideoParams): Promise<StreamVideo>;
7394
/**
7495
* Deletes a video and its copies from Cloudflare Stream.
7596
* @returns A promise that resolves when deletion completes.
97+
* @throws {NotFoundError} if the video is not found
98+
* @throws {InternalError} if an unexpected error occurs
7699
*/
77100
delete(): Promise<void>;
78101
/**
79102
* Creates a signed URL token for a video.
80103
* @returns The signed token that was created.
104+
* @throws {InternalError} if the signing key cannot be retrieved or the token cannot be signed
81105
*/
82106
generateToken(): Promise<string>;
83107

@@ -364,25 +388,40 @@ interface StreamScopedCaptions {
364388
* @param language The BCP 47 language tag for the caption or subtitle.
365389
* @param file The caption or subtitle file to upload.
366390
* @returns The created caption entry.
391+
* @throws {NotFoundError} if the video is not found
392+
* @throws {BadRequestError} if the language or file is invalid
393+
* @throws {MaxFileSizeError} if the file size is too large
394+
* @throws {InternalError} if an unexpected error occurs
367395
*/
368396
upload(language: string, file: File): Promise<StreamCaption>;
369397
/**
370398
* Generate captions or subtitles for the provided language via AI.
371399
* @param language The BCP 47 language tag to generate.
372400
* @returns The generated caption entry.
401+
* @throws {NotFoundError} if the video is not found
402+
* @throws {BadRequestError} if the language is invalid
403+
* @throws {StreamError} if a generated caption already exists
404+
* @throws {StreamError} if the video duration is too long
405+
* @throws {StreamError} if the video is missing audio
406+
* @throws {StreamError} if the requested language is not supported
407+
* @throws {InternalError} if an unexpected error occurs
373408
*/
374409
generate(language: string): Promise<StreamCaption>;
375410
/**
376411
* Lists the captions or subtitles.
377412
* Use the language parameter to filter by a specific language.
378413
* @param language The optional BCP 47 language tag to filter by.
379414
* @returns The list of captions or subtitles.
415+
* @throws {NotFoundError} if the video or caption is not found
416+
* @throws {InternalError} if an unexpected error occurs
380417
*/
381418
list(language?: string): Promise<StreamCaption[]>;
382419
/**
383420
* Removes the captions or subtitles from a video.
384421
* @param language The BCP 47 language tag to remove.
385422
* @returns A promise that resolves when deletion completes.
423+
* @throws {NotFoundError} if the video or caption is not found
424+
* @throws {InternalError} if an unexpected error occurs
386425
*/
387426
delete(language: string): Promise<void>;
388427
}
@@ -393,20 +432,29 @@ interface StreamScopedDownloads {
393432
* types are `default` and `audio`. Defaults to `default` when omitted.
394433
* @param downloadType The download type to create.
395434
* @returns The current downloads for the video.
435+
* @throws {NotFoundError} if the video is not found
436+
* @throws {BadRequestError} if the download type is invalid
437+
* @throws {StreamError} if the video duration is too long to generate a download
438+
* @throws {StreamError} if the video is not ready to stream
439+
* @throws {InternalError} if an unexpected error occurs
396440
*/
397441
generate(
398442
downloadType?: StreamDownloadType
399443
): Promise<StreamDownloadGetResponse>;
400444
/**
401445
* Lists the downloads created for a video.
402446
* @returns The current downloads for the video.
447+
* @throws {NotFoundError} if the video or downloads are not found
448+
* @throws {InternalError} if an unexpected error occurs
403449
*/
404450
get(): Promise<StreamDownloadGetResponse>;
405451
/**
406452
* Delete the downloads for a video. Available types are `default` and `audio`.
407453
* Defaults to `default` when omitted.
408454
* @param downloadType The download type to delete.
409455
* @returns A promise that resolves when deletion completes.
456+
* @throws {NotFoundError} if the video or downloads are not found
457+
* @throws {InternalError} if an unexpected error occurs
410458
*/
411459
delete(downloadType?: StreamDownloadType): Promise<void>;
412460
}
@@ -415,6 +463,8 @@ interface StreamVideos {
415463
/**
416464
* Lists all videos in a users account.
417465
* @returns The list of videos.
466+
* @throws {BadRequestError} if the parameters are invalid
467+
* @throws {InternalError} if an unexpected error occurs
418468
*/
419469
list(params?: StreamVideosListParams): Promise<StreamVideo[]>;
420470
}
@@ -425,6 +475,11 @@ interface StreamWatermarks {
425475
* @param file The image file to upload
426476
* @param params The watermark creation parameters.
427477
* @returns The created watermark profile.
478+
* @throws {BadRequestError} if the parameters are invalid
479+
* @throws {InvalidURLError} if the URL is invalid
480+
* @throws {MaxFileSizeError} if the file size is too large
481+
* @throws {TooManyWatermarksError} if the number of allowed watermarks is reached
482+
* @throws {InternalError} if an unexpected error occurs
428483
*/
429484
generate(
430485
file: File,
@@ -435,6 +490,11 @@ interface StreamWatermarks {
435490
* @param url The image url to upload
436491
* @param params The watermark creation parameters.
437492
* @returns The created watermark profile.
493+
* @throws {BadRequestError} if the parameters are invalid
494+
* @throws {InvalidURLError} if the URL is invalid
495+
* @throws {MaxFileSizeError} if the file size is too large
496+
* @throws {TooManyWatermarksError} if the number of allowed watermarks is reached
497+
* @throws {InternalError} if an unexpected error occurs
438498
*/
439499
generate(
440500
url: string,
@@ -443,18 +503,23 @@ interface StreamWatermarks {
443503
/**
444504
* Lists all watermark profiles for an account.
445505
* @returns The list of watermark profiles.
506+
* @throws {InternalError} if an unexpected error occurs
446507
*/
447508
list(): Promise<StreamWatermark[]>;
448509
/**
449510
* Retrieves details for a single watermark profile.
450511
* @param watermarkId The watermark profile identifier.
451512
* @returns The watermark profile details.
513+
* @throws {NotFoundError} if the watermark is not found
514+
* @throws {InternalError} if an unexpected error occurs
452515
*/
453516
get(watermarkId: string): Promise<StreamWatermark>;
454517
/**
455518
* Deletes a watermark profile.
456519
* @param watermarkId The watermark profile identifier.
457520
* @returns A promise that resolves when deletion completes.
521+
* @throws {NotFoundError} if the watermark is not found
522+
* @throws {InternalError} if an unexpected error occurs
458523
*/
459524
delete(watermarkId: string): Promise<void>;
460525
}
@@ -687,6 +752,47 @@ type StreamPaginationComparison = 'eq' | 'gt' | 'gte' | 'lt' | 'lte';
687752
*/
688753
interface StreamError extends Error {
689754
readonly code: number;
755+
readonly statusCode: number;
690756
readonly message: string;
691757
readonly stack?: string;
692758
}
759+
760+
interface InternalError extends StreamError {
761+
name: 'InternalError';
762+
}
763+
764+
interface BadRequestError extends StreamError {
765+
name: 'BadRequestError';
766+
}
767+
768+
interface NotFoundError extends StreamError {
769+
name: 'NotFoundError';
770+
}
771+
772+
interface ForbiddenError extends StreamError {
773+
name: 'ForbiddenError';
774+
}
775+
776+
interface RateLimitedError extends StreamError {
777+
name: 'RateLimitedError';
778+
}
779+
780+
interface QuotaReachedError extends StreamError {
781+
name: 'QuotaReachedError';
782+
}
783+
784+
interface MaxFileSizeError extends StreamError {
785+
name: 'MaxFileSizeError';
786+
}
787+
788+
interface InvalidURLError extends StreamError {
789+
name: 'InvalidURLError';
790+
}
791+
792+
interface AlreadyUploadedError extends StreamError {
793+
name: 'AlreadyUploadedError';
794+
}
795+
796+
interface TooManyWatermarksError extends StreamError {
797+
name: 'TooManyWatermarksError';
798+
}

0 commit comments

Comments
 (0)