@rmdes/indiekit-endpoint-microsub 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/controllers/reader.js +17 -3
- package/package.json +1 -1
|
@@ -376,7 +376,7 @@ export async function submitCompose(request, response) {
|
|
|
376
376
|
if (!micropubEndpoint) {
|
|
377
377
|
return response.status(500).render("error", {
|
|
378
378
|
title: "Error",
|
|
379
|
-
|
|
379
|
+
content: "Micropub endpoint not configured",
|
|
380
380
|
});
|
|
381
381
|
}
|
|
382
382
|
|
|
@@ -450,20 +450,34 @@ export async function submitCompose(request, response) {
|
|
|
450
450
|
|
|
451
451
|
// Handle error
|
|
452
452
|
const errorBody = await micropubResponse.text();
|
|
453
|
+
const statusText = micropubResponse.statusText || "Unknown error";
|
|
453
454
|
console.error(
|
|
454
455
|
`[Microsub] Micropub error: ${micropubResponse.status} ${errorBody}`,
|
|
455
456
|
);
|
|
456
457
|
|
|
458
|
+
// Parse error message from response body if JSON
|
|
459
|
+
let errorMessage = `Micropub error: ${statusText}`;
|
|
460
|
+
try {
|
|
461
|
+
const errorJson = JSON.parse(errorBody);
|
|
462
|
+
if (errorJson.error_description) {
|
|
463
|
+
errorMessage = String(errorJson.error_description);
|
|
464
|
+
} else if (errorJson.error) {
|
|
465
|
+
errorMessage = String(errorJson.error);
|
|
466
|
+
}
|
|
467
|
+
} catch {
|
|
468
|
+
// Not JSON, use status text
|
|
469
|
+
}
|
|
470
|
+
|
|
457
471
|
return response.status(micropubResponse.status).render("error", {
|
|
458
472
|
title: "Error",
|
|
459
|
-
|
|
473
|
+
content: errorMessage,
|
|
460
474
|
});
|
|
461
475
|
} catch (error) {
|
|
462
476
|
console.error(`[Microsub] Micropub request failed: ${error.message}`);
|
|
463
477
|
|
|
464
478
|
return response.status(500).render("error", {
|
|
465
479
|
title: "Error",
|
|
466
|
-
|
|
480
|
+
content: `Failed to create post: ${error.message}`,
|
|
467
481
|
});
|
|
468
482
|
}
|
|
469
483
|
}
|
package/package.json
CHANGED