Browse Source

Requete GET : ok

Lou 3 years ago
parent
commit
fd5793a1ef
2 changed files with 9 additions and 7 deletions
  1. 1
    1
      src/pages/Login/index.jsx
  2. 8
    6
      src/services/request/Get.js

+ 1
- 1
src/pages/Login/index.jsx View File

@@ -9,7 +9,7 @@ const LoginPage = () => {
9 9
 
10 10
 	useEffect(() => {
11 11
 		console.log("HELLO 2");
12
-		let response = get("/users", jwt_token);
12
+		let response = get("/users/1", jwt_token);
13 13
 		console.log("HELLO 3");
14 14
 		console.log(response);
15 15
 	}, []);

+ 8
- 6
src/services/request/Get.js View File

@@ -1,7 +1,6 @@
1 1
 import axios from 'axios';
2 2
 import { BASE_URL } from "./config.js";
3 3
 
4
-
5 4
 const get = async (
6 5
   endpoint,
7 6
   jwt_token = null,
@@ -12,11 +11,14 @@ const get = async (
12 11
       opt["Authorization"] = jwt_token
13 12
   }
14 13
 
15
-  console.log("HELLO 1");
16
-  const response = await axios.get(BASE_URL + endpoint, { headers: opt })
17
-  console.log(response.data);
18
-  return response.data
19
-
14
+  try {
15
+    console.log("HELLO 1");
16
+    const response = await axios.get(BASE_URL + endpoint, { headers: opt })
17
+    console.log(response.data);
18
+    return response.data
19
+  } catch (err) {
20
+    console.error(`An error occurred while trying to fetch` + endpoint + `:` + err);
21
+  }
20 22
 }
21 23
 
22 24
 export default get;

Loading…
Cancel
Save