カード情報の取得に失敗した時にちゃんと処理を中断させる

This commit is contained in:
shibafu 2020-08-23 13:43:31 +09:00
parent d1f14ed271
commit 24a74c4c2c

View File

@ -1,4 +1,4 @@
import { fetchGet } from './fetch'; import { fetchGet, ResponseError } from './fetch';
export function suicide<T>(e: T) { export function suicide<T>(e: T) {
return function (): never { return function (): never {
@ -15,7 +15,12 @@ export function linkCard(el: Element) {
} }
fetchGet('/api/checkin/card', { url }) fetchGet('/api/checkin/card', { url })
.then((response) => response.json()) .then((response) => {
if (response.ok) {
return response.json();
}
throw new ResponseError(response);
})
.then((data) => { .then((data) => {
const metaColumn = el.querySelector('.col-12:last-of-type') || die(); const metaColumn = el.querySelector('.col-12:last-of-type') || die();
const imageColumn = el.querySelector<HTMLElement>('.col-12:first-of-type') || die(); const imageColumn = el.querySelector<HTMLElement>('.col-12:first-of-type') || die();