From dea548cd4a939ba0db02971ac995074cbb134009 Mon Sep 17 00:00:00 2001 From: monoid Date: Sun, 10 Jan 2021 19:05:13 +0900 Subject: [PATCH] not ok throw Error --- src/client/accessor/contents.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/client/accessor/contents.ts b/src/client/accessor/contents.ts index f8014ea..d35353c 100644 --- a/src/client/accessor/contents.ts +++ b/src/client/accessor/contents.ts @@ -3,16 +3,27 @@ import {toQueryString} from './util'; const baseurl = "/content"; export * from "../../model/contents"; + +export class FetchFailError implements Error{ + name: string; + message: string; + stack?: string; + constructor(message:string,stack?:string){ + this.name = "Fetch Fail"; + this.message = message; + this.stack = stack; + } +} export class ClientContentAccessor implements ContentAccessor{ async findList(option?: QueryListOption | undefined): Promise{ let res = await fetch(`${baseurl}/search?${option !== undefined ? toQueryString(option) : ""}`); - //if(res.status !== 200); + if(res.status !== 200) throw new FetchFailError("findList Failed"); let ret = await res.json(); return ret; } async findById(id: number, tagload?: boolean | undefined): Promise{ let res = await fetch(`${baseurl}/${id}`); - if(res.status !== 200) return undefined; + if(res.status !== 200) throw new FetchFailError("findById Failed");; let ret = await res.json(); return ret; }