fix: error class

This commit is contained in:
monoid 2022-06-29 17:02:40 +09:00
parent d746b36ba6
commit 853d9fd0fa
1 changed files with 3 additions and 10 deletions

View File

@ -4,16 +4,8 @@ const baseurl = "/api/doc";
export * from "../../model/doc"; export * from "../../model/doc";
export class FetchFailError implements Error{ export class FetchFailError extends Error{}
name: string;
message: string;
stack?: string;
constructor(message:string,stack?:string){
this.name = "Fetch Fail";
this.message = message;
this.stack = stack;
}
}
export class ClientDocumentAccessor implements DocumentAccessor{ export class ClientDocumentAccessor implements DocumentAccessor{
search: (search_word: string) => Promise<Document[]>; search: (search_word: string) => Promise<Document[]>;
addList: (content_list: DocumentBody[]) => Promise<number[]>; addList: (content_list: DocumentBody[]) => Promise<number[]>;
@ -25,6 +17,7 @@ export class ClientDocumentAccessor implements DocumentAccessor{
}; };
async findList(option?: QueryListOption | undefined): Promise<Document[]>{ async findList(option?: QueryListOption | undefined): Promise<Document[]>{
let res = await fetch(`${baseurl}/search?${option !== undefined ? toQueryString(option) : ""}`); let res = await fetch(`${baseurl}/search?${option !== undefined ? toQueryString(option) : ""}`);
if(res.status == 401) throw new FetchFailError("Unauthorized")
if(res.status !== 200) throw new FetchFailError("findList Failed"); if(res.status !== 200) throw new FetchFailError("findList Failed");
let ret = await res.json(); let ret = await res.json();
return ret; return ret;