add test log

This commit is contained in:
LittleBoy 2024-06-05 00:26:46 +08:00
parent aabbd75a2f
commit d3c83842f4
4 changed files with 35 additions and 13 deletions

View File

@ -3,6 +3,7 @@ import {Button, Modal, Notification, Popconfirm, Space} from "@douyinfe/semi-ui"
import {useState} from "react"; import {useState} from "react";
import {useRequest} from "ahooks"; import {useRequest} from "ahooks";
import {useTranslation} from "react-i18next"; import {useTranslation} from "react-i18next";
import * as Sentry from "@sentry/react";
import SearchForm from "@/components/bill/search-form.tsx"; import SearchForm from "@/components/bill/search-form.tsx";
import BillDetail from "@/components/bill/detail.tsx"; import BillDetail from "@/components/bill/detail.tsx";
@ -13,15 +14,24 @@ import {useDownloadReceiptPDF} from "@/service/generate-pdf.ts";
const BillQuery = () => { const BillQuery = () => {
const [showBill, setShowBill] = useState<BillModel>() const [showBill, setShowBill] = useState<BillModel>()
const [queryParams, setBillQueryParams] = useState<BillQueryParams>({}); const [queryParams, setBillQueryParams] = useState<BillQueryParams>({});
const {data, loading,refresh} = useRequest(() => billList(queryParams), { const {data, loading, refresh} = useRequest(() => billList(queryParams), {
refreshDeps: [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 {t} = useTranslation()
const onConfirmCancel = (bill:BillModel)=>{ const onConfirmCancel = (bill: BillModel) => {
cancelBill(bill.id).then(()=>{ cancelBill(bill.id).then(() => {
Notification.success({title:'Notice',content:t('bill.cancel_success')}) Notification.success({title: 'Notice', content: t('bill.cancel_success')})
refresh() refresh()
}) })
} }
@ -31,11 +41,12 @@ const BillQuery = () => {
<Popconfirm <Popconfirm
title={'Notice'} title={'Notice'}
content={`${t('bill.cancel_confirm')}?`} content={`${t('bill.cancel_confirm')}?`}
onConfirm={()=>onConfirmCancel(bill)} onConfirm={() => onConfirmCancel(bill)}
> >
<Button size={'small'} theme={'solid'} type={'primary'}>{t('bill.cancel')}</Button> <Button size={'small'} theme={'solid'} type={'primary'}>{t('bill.cancel')}</Button>
</Popconfirm> </Popconfirm>
<Button onClick={() => setShowBill(bill)} size={'small'} theme={'solid'} type={'primary'}>{t('base.qr-code')}</Button> <Button onClick={() => setShowBill(bill)} size={'small'} theme={'solid'}
type={'primary'}>{t('base.qr-code')}</Button>
{AppMode == 'development' && <a href={`/pay?bill=${bill.id}`} target={'_blank'}>Payment</a>} {AppMode == 'development' && <a href={`/pay?bill=${bill.id}`} target={'_blank'}>Payment</a>}
</>} </>}
{ {
@ -51,7 +62,7 @@ const BillQuery = () => {
<BillList <BillList
type={'query'} loading={loading} type={'query'} loading={loading}
operationRender={operation} source={data} operationRender={operation} source={data}
onPageChange={(page_number) =>{ onPageChange={(page_number) => {
setBillQueryParams({ setBillQueryParams({
...queryParams, ...queryParams,
page_number page_number

View File

@ -12,6 +12,7 @@ import {useSetState} from "ahooks";
import {BizError} from "@/service/types.ts"; import {BizError} from "@/service/types.ts";
import {IconAlertTriangle} from "@douyinfe/semi-icons"; import {IconAlertTriangle} from "@douyinfe/semi-icons";
import dayjs from "dayjs"; import dayjs from "dayjs";
import * as Sentry from '@sentry/react'
@ -26,7 +27,7 @@ export default function Index() {
}) })
const handleSubmit = (values: ManualCreateBillParam) => { const handleSubmit = (values: ManualCreateBillParam) => {
setState({loading: true}) setState({loading: true,errorMessage:''})
createManualBill(values).then((ret) => { createManualBill(values).then((ret) => {
frm.current?.formApi.reset(); frm.current?.formApi.reset();
Toast.info({ Toast.info({
@ -34,6 +35,14 @@ export default function Index() {
}) })
getBillDetail(ret.id).then(setBillInfo); getBillDetail(ret.id).then(setBillInfo);
}).catch((e: BizError) => { }).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}) setState({errorMessage: e.message})
}).finally(() => { }).finally(() => {
setState({loading: false}) setState({loading: false})

View File

@ -39,7 +39,7 @@ export function request<T>(url: string, method: RequestMethod, data: AllType = n
return; return;
} }
// const // const
const {code, message, data} = res.data const {code, message, data,request_id} = res.data
if (code == 0) { if (code == 0) {
if (getOriginResult) { if (getOriginResult) {
resolve(res.data as unknown as T) resolve(res.data as unknown as T)
@ -47,7 +47,7 @@ export function request<T>(url: string, method: RequestMethod, data: AllType = n
} }
resolve(data as unknown as T) resolve(data as unknown as T)
} else { } 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 => { }).catch(e => {
reject(new BizError(e.message, 500)) reject(new BizError(e.message, 500))

View File

@ -3,10 +3,12 @@ export class BizError extends Error {
* *
*/ */
code = 1; code = 1;
request_id = '';
data: string | number | object | undefined | null; data: string | number | object | undefined | null;
constructor(message: string, code = 1, data?: AllType) { constructor(message: string, code = 1,request_id='', data?: AllType) {
super(message); super(message);
this.request_id = request_id;
this.code = code; this.code = code;
this.data = data; this.data = data;
} }