Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const axios = require('axios');
|
| 2 |
+
|
| 3 |
+
const apiUrl = 'https://odgj.rikipurwanto.repl.co/api/gpt?q=apa%20itu%20ikan&key=global';
|
| 4 |
+
|
| 5 |
+
axios.get(apiUrl)
|
| 6 |
+
.then(response => {
|
| 7 |
+
console.log(response.data);
|
| 8 |
+
})
|
| 9 |
+
.catch(error => {
|
| 10 |
+
if (error.response) {
|
| 11 |
+
// Server merespons dengan kode status di luar rentang 2xx
|
| 12 |
+
console.error('Response Error:', error.response.status, error.response.data);
|
| 13 |
+
} else if (error.request) {
|
| 14 |
+
// Tidak ada respons dari server
|
| 15 |
+
console.error('Request Error:', error.request);
|
| 16 |
+
} else {
|
| 17 |
+
// Terjadi kesalahan lainnya
|
| 18 |
+
console.error('Error:', error.message);
|
| 19 |
+
}
|
| 20 |
+
});
|