diff --git a/src/pages/bill/query.tsx b/src/pages/bill/query.tsx index 49ce4ae..0b5cfb3 100644 --- a/src/pages/bill/query.tsx +++ b/src/pages/bill/query.tsx @@ -3,6 +3,7 @@ import {Button, Modal, Notification, Popconfirm, Space} from "@douyinfe/semi-ui" import {useState} from "react"; import {useRequest} from "ahooks"; import {useTranslation} from "react-i18next"; +import * as Sentry from "@sentry/react"; import SearchForm from "@/components/bill/search-form.tsx"; import BillDetail from "@/components/bill/detail.tsx"; @@ -13,15 +14,24 @@ import {useDownloadReceiptPDF} from "@/service/generate-pdf.ts"; const BillQuery = () => { const [showBill, setShowBill] = useState() const [queryParams, setBillQueryParams] = useState({}); - const {data, loading,refresh} = useRequest(() => billList(queryParams), { - refreshDeps: [queryParams] + const {data, loading, refresh} = useRequest(() => billList(queryParams), { + refreshDeps: [queryParams], + onError: (e) => { + Sentry.captureMessage('Error: Query bill error', { + level: 'error', + extra: { + message: e.message, + ...queryParams + } + }); + } }) - const {loading:downloading,downloadPDF } = useDownloadReceiptPDF() + const {loading: downloading, downloadPDF} = useDownloadReceiptPDF() const {t} = useTranslation() - const onConfirmCancel = (bill:BillModel)=>{ - cancelBill(bill.id).then(()=>{ - Notification.success({title:'Notice',content:t('bill.cancel_success')}) + const onConfirmCancel = (bill: BillModel) => { + cancelBill(bill.id).then(() => { + Notification.success({title: 'Notice', content: t('bill.cancel_success')}) refresh() }) } @@ -31,11 +41,12 @@ const BillQuery = () => { onConfirmCancel(bill)} + onConfirm={() => onConfirmCancel(bill)} > - + {AppMode == 'development' && Payment} } { @@ -51,7 +62,7 @@ const BillQuery = () => { { + onPageChange={(page_number) => { setBillQueryParams({ ...queryParams, page_number diff --git a/src/pages/manual/index.tsx b/src/pages/manual/index.tsx index e359451..1974bea 100644 --- a/src/pages/manual/index.tsx +++ b/src/pages/manual/index.tsx @@ -12,6 +12,7 @@ import {useSetState} from "ahooks"; import {BizError} from "@/service/types.ts"; import {IconAlertTriangle} from "@douyinfe/semi-icons"; import dayjs from "dayjs"; +import * as Sentry from '@sentry/react' @@ -26,7 +27,7 @@ export default function Index() { }) const handleSubmit = (values: ManualCreateBillParam) => { - setState({loading: true}) + setState({loading: true,errorMessage:''}) createManualBill(values).then((ret) => { frm.current?.formApi.reset(); Toast.info({ @@ -34,6 +35,14 @@ export default function Index() { }) getBillDetail(ret.id).then(setBillInfo); }).catch((e: BizError) => { + Sentry.captureMessage('Error: create manual bill error',{ + level: 'error', + extra: { + message:e.message, + request_id:e.request_id, + ...values + } + }); setState({errorMessage: e.message}) }).finally(() => { setState({loading: false}) diff --git a/src/service/request.ts b/src/service/request.ts index 6dcde69..77e039a 100644 --- a/src/service/request.ts +++ b/src/service/request.ts @@ -39,7 +39,7 @@ export function request(url: string, method: RequestMethod, data: AllType = n return; } // const - const {code, message, data} = res.data + const {code, message, data,request_id} = res.data if (code == 0) { if (getOriginResult) { resolve(res.data as unknown as T) @@ -47,7 +47,7 @@ export function request(url: string, method: RequestMethod, data: AllType = n } resolve(data as unknown as T) } else { - reject(new BizError(message, code, data as unknown as AllType)) + reject(new BizError(message, code,request_id, data as unknown as AllType)) } }).catch(e => { reject(new BizError(e.message, 500)) diff --git a/src/service/types.ts b/src/service/types.ts index d72300f..af6c526 100644 --- a/src/service/types.ts +++ b/src/service/types.ts @@ -3,10 +3,12 @@ export class BizError extends Error { * 错误码 */ code = 1; + request_id = ''; data: string | number | object | undefined | null; - constructor(message: string, code = 1, data?: AllType) { + constructor(message: string, code = 1,request_id='', data?: AllType) { super(message); + this.request_id = request_id; this.code = code; this.data = data; }