11import type {
22 Author ,
33 Chapter ,
4- WorkContent ,
54 LockedWorkSummary ,
5+ WorkContent ,
66 WorkSummary ,
77} from "types/entities" ;
88import {
9- getChaptersList ,
10- getWorkAuthors as getWorkAuthorsFromChaptersIndex ,
11- getWorkTitle as getWorkTitleFromChaptersIndex ,
12- } from "./chapter-getters" ;
9+ InvalidIDError ,
10+ isValidArchiveId ,
11+ isValidArchiveIdOrNullish ,
12+ parseArchiveId ,
13+ } from "src/utils" ;
1314import {
1415 getChapterIndex ,
1516 getChapterName ,
@@ -41,12 +42,12 @@ import {
4142 getWorkWarnings ,
4243 getWorkWordCount ,
4344} from "./work-getters" ;
44- import { loadChaptersIndexPage , loadWorkPage } from "src/page-loaders" ;
4545import {
46- isValidArchiveId ,
47- parseArchiveId ,
48- isValidArchiveIdOrNullish ,
49- } from "src/utils" ;
46+ getChaptersList ,
47+ getWorkAuthors as getWorkAuthorsFromChaptersIndex ,
48+ getWorkTitle as getWorkTitleFromChaptersIndex ,
49+ } from "./chapter-getters" ;
50+ import { loadChaptersIndexPage , loadWorkPage } from "src/page-loaders" ;
5051
5152export const getWork = async ( {
5253 workId,
@@ -56,10 +57,10 @@ export const getWork = async ({
5657 chapterId ?: string | number ;
5758} ) : Promise < WorkSummary | LockedWorkSummary > => {
5859 if ( ! isValidArchiveId ( workId ) ) {
59- throw new Error ( ` ${ workId } is not a valid work id` ) ;
60+ throw new InvalidIDError ( workId , " work" ) ;
6061 }
6162 if ( ! isValidArchiveIdOrNullish ( chapterId ) ) {
62- throw new Error ( ` ${ workId } is not a valid chapter id` ) ;
63+ throw new InvalidIDError ( workId , " chapter" ) ;
6364 }
6465
6566 const workPage = await loadWorkPage ( { workId, chapterId } ) ;
@@ -134,7 +135,7 @@ export const getWorkWithChapters = async ({
134135 chapters : Chapter [ ] ;
135136} > => {
136137 if ( ! isValidArchiveId ( workId ) ) {
137- throw new Error ( ` ${ workId } is not a valid work id` ) ;
138+ throw new InvalidIDError ( workId , " work" ) ;
138139 }
139140 const page = await loadChaptersIndexPage ( { workId } ) ;
140141
@@ -154,7 +155,7 @@ export const getWorkContent = async ({
154155 chapterId ?: string | number | null ;
155156} ) : Promise < WorkContent > => {
156157 if ( ! isValidArchiveId ( workId ) || ! isValidArchiveIdOrNullish ( chapterId ) ) {
157- throw new Error ( ` ${ workId } is not a valid work id` ) ;
158+ throw new InvalidIDError ( workId , " work" ) ;
158159 }
159160 const workPage = await loadWorkPage ( {
160161 workId,
0 commit comments