add & edit time rezerv
This commit is contained in:
+13
-3
@@ -40,9 +40,19 @@ export async function api<T>(path: string, options: ApiOptions = {}): Promise<T>
|
||||
const body = (await res.json().catch(() => null)) as
|
||||
| { message?: string | string[] }
|
||||
| null;
|
||||
const msg = Array.isArray(body?.message)
|
||||
? body.message.join(', ')
|
||||
: body?.message ?? res.statusText;
|
||||
let msg: string;
|
||||
if (Array.isArray(body?.message)) {
|
||||
const lines = body.message.map(String);
|
||||
const timeErrors = lines.filter((l) =>
|
||||
/startTime|endTime/.test(l) && /regular expression|HH:mm/i.test(l),
|
||||
);
|
||||
msg =
|
||||
timeErrors.length > 0
|
||||
? 'فرمت ساعت نامعتبر است. لطفاً دوباره بازه را اضافه و ذخیره کنید.'
|
||||
: lines.join(' · ');
|
||||
} else {
|
||||
msg = body?.message ?? res.statusText;
|
||||
}
|
||||
throw new ApiError(res.status, msg);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user