Skip to content

Commit

Permalink
fix: let axios error go away
Browse files Browse the repository at this point in the history
  • Loading branch information
EINDEX committed Jun 15, 2023
1 parent e870c90 commit c0bed75
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/memos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ export default class MemosClient {


private async request<T>(url: string, method: string, payload: any): Promise<T> {
const resp: AxiosResponse<MemosAPIResponse<T>> = await axios({
method: method,
url: url,
data: payload,
});
if (resp.status !== 200) {
throw "Connect issue";
} else if (resp.status >= 400 && resp.status < 500) {
throw resp.data?.message || "Error occurred";
try {
const resp: AxiosResponse<MemosAPIResponse<T>> = await axios({
method: method,
url: url,
data: payload,
});
if (resp.status !== 200) {
throw "Something wrong!";
} else if (resp.status >= 400 && resp.status < 500) {
throw resp.data?.message || "Error occurred";
}
const data = resp.data.data;
return data;
} catch ( error) {
throw "Cannot connect to memos server";
}
const data = resp.data.data;
return data;

}

public async getMemos(
Expand Down

0 comments on commit c0bed75

Please sign in to comment.