@@ -8,6 +8,12 @@ import type {
8
8
import { type BaseOptions , setDefaults } from "../../util.ts" ;
9
9
import { cookie } from "../../rest/auth.ts" ;
10
10
import type { ResponseOfEndpoint } from "../../targeted_response.ts" ;
11
+ import {
12
+ type HTTPError ,
13
+ makeError ,
14
+ makeHTTPError ,
15
+ type TypedError ,
16
+ } from "../../error.ts" ;
11
17
12
18
/** Options for {@linkcode listPages} */
13
19
export interface ListPagesOption < R extends Response | undefined >
@@ -99,7 +105,7 @@ export const get = <R extends Response | undefined = Response>(
99
105
*
100
106
* @param project The project name to list pages from
101
107
* @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
103
109
*/
104
110
export async function * list (
105
111
project : string ,
@@ -108,8 +114,19 @@ export async function* list(
108
114
const props = { ...( options ?? { } ) , skip : options ?. skip ?? 0 } ;
109
115
while ( true ) {
110
116
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 ;
113
130
}
114
131
const list = await response . json ( ) ;
115
132
yield * list . pages ;
@@ -119,7 +136,3 @@ export async function* list(
119
136
}
120
137
121
138
export * as title from "./project/title.ts" ;
122
-
123
- export interface HTTPError extends Error {
124
- readonly cause : Response ;
125
- }
0 commit comments