Skip to content

Commit 15d1f6e

Browse files
committed
fix #3
1 parent 07fa01b commit 15d1f6e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codingapi/ui-framework",
3-
"version": "0.0.26",
3+
"version": "0.0.27",
44
"description": "A UI Framework built with React and Typescript",
55
"keywords": [
66
"ui",

playground/src/components/HttpTest.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from "react";
22
import Space from "@/components/Space";
3-
//@ts-ignore
43
import {HttpClient,Response} from "@codingapi/ui-framework";
54

65
const httpClient = new HttpClient(10000,{

src/utils/http.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export class HttpClient {
1919
private readonly api: AxiosInstance;
2020
private readonly messageBox: MessageBox;
2121

22-
constructor(timeout: number, messageBox: MessageBox) {
22+
constructor(timeout: number, messageBox: MessageBox, baseUrl = '') {
2323
this.messageBox = messageBox;
2424
this.api = axios.create({
2525
timeout: timeout,
26+
baseURL: baseUrl,
2627
headers: {
2728
"Content-Type": "application/json",
2829
},
@@ -104,9 +105,11 @@ export class HttpClient {
104105
params
105106
});
106107
return response.data as Response;
107-
} catch (e) {
108+
} catch (err:any) {
108109
return {
109110
success: false,
111+
errMessage:err.message,
112+
errCode:'http.error'
110113
}
111114
}
112115
}
@@ -115,9 +118,11 @@ export class HttpClient {
115118
try {
116119
const response = await this.api.put(url, data);
117120
return response.data as Response;
118-
} catch (e) {
121+
} catch (err:any) {
119122
return {
120123
success: false,
124+
errMessage:err.message,
125+
errCode:'http.error'
121126
}
122127
}
123128
}
@@ -128,9 +133,11 @@ export class HttpClient {
128133
params
129134
});
130135
return response.data as Response;
131-
} catch (e) {
136+
} catch (err:any) {
132137
return {
133138
success: false,
139+
errMessage:err.message,
140+
errCode:'http.error'
134141
}
135142
}
136143
}
@@ -139,9 +146,11 @@ export class HttpClient {
139146
try {
140147
const response = await this.api.post(url, data);
141148
return response.data as Response;
142-
} catch (e) {
149+
} catch (err:any) {
143150
return {
144151
success: false,
152+
errMessage:err.message,
153+
errCode:'http.error'
145154
}
146155
}
147156
}

0 commit comments

Comments
 (0)