@@ -5,8 +5,7 @@ import type {
55 SearchedTitle ,
66} from "../deps/scrapbox-rest.ts" ;
77import { cookie } from "./auth.ts" ;
8- import { UnexpectedResponseError } from "./error.ts" ;
9- import { tryToErrorLike } from "../is.ts" ;
8+ import { makeError } from "./error.ts" ;
109import { BaseOptions , Result , setDefaults } from "./util.ts" ;
1110
1211/** 不正なfollowingIdを渡されたときに発生するエラー */
@@ -33,15 +32,16 @@ export const getLinks = async (
3332 } , NotFoundError | NotLoggedInError | InvalidFollowingIdError >
3433> => {
3534 const { sid, hostName, fetch, followingId } = setDefaults ( options ?? { } ) ;
36- const path = `https://${ hostName } /api/pages/${ project } /search/titles${
37- followingId ? `?followingId=${ followingId } ` : ""
38- } `;
3935
40- const res = await fetch (
41- path ,
36+ const req = new Request (
37+ `https://${ hostName } /api/pages/${ project } /search/titles${
38+ followingId ? `?followingId=${ followingId } ` : ""
39+ } `,
4240 sid ? { headers : { Cookie : cookie ( sid ) } } : undefined ,
4341 ) ;
4442
43+ const res = await fetch ( req ) ;
44+
4545 if ( ! res . ok ) {
4646 if ( res . status === 422 ) {
4747 return {
@@ -52,17 +52,10 @@ export const getLinks = async (
5252 } ,
5353 } ;
5454 }
55- const text = await res . text ( ) ;
56- const value = tryToErrorLike ( text ) ;
57- if ( ! value ) {
58- throw new UnexpectedResponseError ( {
59- path : new URL ( path ) ,
60- ...res ,
61- body : text ,
62- } ) ;
63- }
64- return { ok : false , value : value as NotFoundError | NotLoggedInError } ;
55+
56+ return makeError < NotFoundError | NotLoggedInError > ( req , res ) ;
6557 }
58+
6659 const pages = ( await res . json ( ) ) as SearchedTitle [ ] ;
6760 return {
6861 ok : true ,
0 commit comments