Skip to content

Commit 4b8e5f2

Browse files
committed
Revert "refactor: add try catch to server/api endpoints"
This reverts commit aad61aa.
1 parent aad61aa commit 4b8e5f2

File tree

2 files changed

+33
-44
lines changed

2 files changed

+33
-44
lines changed

server/api/login.post.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
export default defineEventHandler(async (event) => {
2-
try {
3-
const config = useRuntimeConfig()
4-
const body = await readBody(event)
2+
const config = useRuntimeConfig()
3+
const body = await readBody(event)
54

6-
const url = `${config.public.COMMUNITY_API_URL}/auth/`
7-
const loginOptions = {
8-
method: "POST",
9-
body: body,
10-
headers: {
11-
"Accept": "*/*",
12-
"Content-Type": "application/json"
13-
}
5+
const url = `${config.public.COMMUNITY_API_URL}/auth/`
6+
const loginOptions = {
7+
method: "POST",
8+
body: body,
9+
headers: {
10+
"Accept": "*/*",
11+
"Content-Type": "application/json"
1412
}
13+
}
1514

16-
const loginResponse = await $fetch.raw(url + 'login', loginOptions);
17-
18-
const authResponse = await $fetch.raw(url, {
19-
method: 'GET',
20-
headers: {
21-
"Accept": "*/*",
22-
"Cookie": loginResponse.headers.get('set-cookie')
23-
}
24-
})
25-
appendHeader(event, 'Set-Cookie', loginResponse.headers.get('set-cookie')) // assuming we only set one cookie
26-
return authResponse._data
15+
const loginResponse = await $fetch.raw(url + 'login', loginOptions);
2716

28-
} catch (error) {
29-
console.log(error);
30-
return false;
31-
}
17+
const authResponse = await $fetch.raw(url, {
18+
method: 'GET',
19+
headers: {
20+
"Accept": "*/*",
21+
"Cookie": loginResponse.headers.get('set-cookie')
22+
}
23+
})
24+
appendHeader(event, 'Set-Cookie', loginResponse.headers.get('set-cookie')) // assuming we only set one cookie
25+
return authResponse._data
3226
});

server/api/member/index.get.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
export default defineEventHandler(async (event) => {
2-
try {
3-
const query = getQuery(event)
4-
const config = useRuntimeConfig()
5-
const sessionCookie = getCookie(event, `${config.public.SESSION_COOKIE_NAME}`);
2+
const query = getQuery(event)
3+
const config = useRuntimeConfig()
4+
const sessionCookie = getCookie(event, `${config.public.SESSION_COOKIE_NAME}`);
65

7-
const url = `${config.public.COMMUNITY_API_URL}/member/${query.id}`
8-
const options = {
9-
method: "GET",
10-
headers: {
11-
"Accept": "*/*",
12-
"Content-Type": "application/json",
13-
"Cookie": `${config.public.SESSION_COOKIE_NAME}=` + sessionCookie,
14-
}
6+
const url = `${config.public.COMMUNITY_API_URL}/member/${query.id}`
7+
const options = {
8+
method: "GET",
9+
headers: {
10+
"Accept": "*/*",
11+
"Content-Type": "application/json",
12+
"Cookie": `${config.public.SESSION_COOKIE_NAME}=` + sessionCookie,
1513
}
16-
17-
const response = await $fetch.raw(url, options);
18-
return response._data
19-
} catch (error) {
20-
console.log(error);
21-
return false;
2214
}
15+
16+
const response = await $fetch.raw(url, options);
17+
return response._data
2318
});

0 commit comments

Comments
 (0)