Skip to content

Commit 4193c50

Browse files
committed
Replace body-parser usage and handle fetch errors
1 parent b49b2ed commit 4193c50

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

facebook-manager/server.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const express = require('express');
22
const path = require('path');
3-
const bodyParser = require('body-parser');
43

54
const PAGE_ID = process.env.FB_PAGE_ID; // Techno auf den Augen page ID
65
const ACCESS_TOKEN = process.env.FB_ACCESS_TOKEN; // long-lived Page access token
@@ -13,13 +12,16 @@ if (!PAGE_ID || !ACCESS_TOKEN) {
1312
}
1413

1514
const app = express();
16-
app.use(bodyParser.json());
15+
app.use(express.json());
1716
app.use(express.static(path.join(__dirname, 'public')));
1817

1918
app.get('/api/posts', async (req, res) => {
2019
try {
2120
const response = await fetch(`${GRAPH_URL}/${PAGE_ID}/posts?access_token=${ACCESS_TOKEN}`);
2221
const data = await response.json();
22+
if (!response.ok) {
23+
return res.status(response.status).json(data);
24+
}
2325
res.json(data);
2426
} catch (e) {
2527
res.status(500).json({ error: 'Failed to fetch posts', details: e.message });
@@ -38,6 +40,9 @@ app.post('/api/posts', async (req, res) => {
3840
body: JSON.stringify({ message }),
3941
});
4042
const data = await response.json();
43+
if (!response.ok) {
44+
return res.status(response.status).json(data);
45+
}
4146
res.json(data);
4247
} catch (e) {
4348
res.status(500).json({ error: 'Failed to create post', details: e.message });

0 commit comments

Comments
 (0)