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 {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<BillModel>()
const [queryParams, setBillQueryParams] = useState<BillQueryParams>({});
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 = () => {
<Popconfirm
title={'Notice'}
content={`${t('bill.cancel_confirm')}?`}
onConfirm={()=>onConfirmCancel(bill)}
onConfirm={() => onConfirmCancel(bill)}
>
<Button size={'small'} theme={'solid'} type={'primary'}>{t('bill.cancel')}</Button>
</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>}
</>}
{
@ -51,7 +62,7 @@ const BillQuery = () => {
<BillList
type={'query'} loading={loading}
operationRender={operation} source={data}
onPageChange={(page_number) =>{
onPageChange={(page_number) => {
setBillQueryParams({
...queryParams,
page_number

View File

@ -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})

View File

@ -39,7 +39,7 @@ export function request<T>(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<T>(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))

View File

@ -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;
}