@@ -8,6 +8,12 @@ import type {
88import { type BaseOptions , setDefaults } from "../../util.ts" ;
99import { cookie } from "../../rest/auth.ts" ;
1010import type { ResponseOfEndpoint } from "../../targeted_response.ts" ;
11+ import {
12+ type HTTPError ,
13+ makeError ,
14+ makeHTTPError ,
15+ type TypedError ,
16+ } from "../../error.ts" ;
1117
1218/** Options for {@linkcode listPages} */
1319export interface ListPagesOption < R extends Response | undefined >
@@ -99,7 +105,7 @@ export const get = <R extends Response | undefined = Response>(
99105 *
100106 * @param project The project name to list pages from
101107 * @param options Configuration options for pagination and sorting
102- * @throws {HTTPError } If any requests in the pagination sequence fail
108+ * @throws {HTTPError | TypedError<"NotLoggedInError" | "NotMemberError" | "NotFoundError"> } If any requests in the pagination sequence fail
103109 */
104110export async function * list (
105111 project : string ,
@@ -108,8 +114,19 @@ export async function* list(
108114 const props = { ...( options ?? { } ) , skip : options ?. skip ?? 0 } ;
109115 while ( true ) {
110116 const response = await get ( project , props ) ;
111- if ( response . status !== 200 ) {
112- throw new Error ( response . statusText , { cause : response } ) as HTTPError ;
117+ switch ( response . status ) {
118+ case 200 :
119+ break ;
120+ case 401 :
121+ case 403 :
122+ case 404 : {
123+ const error = await response . json ( ) ;
124+ throw makeError ( error . name , error . message ) satisfies TypedError <
125+ "NotLoggedInError" | "NotMemberError" | "NotFoundError"
126+ > ;
127+ }
128+ default :
129+ throw makeHTTPError ( response ) satisfies HTTPError ;
113130 }
114131 const list = await response . json ( ) ;
115132 yield * list . pages ;
@@ -119,7 +136,3 @@ export async function* list(
119136}
120137
121138export * as title from "./project/title.ts" ;
122-
123- export interface HTTPError extends Error {
124- readonly cause : Response ;
125- }
0 commit comments