2c0cfffd54
Implement the Mastodon Client REST API (/api/v1/*, /api/v2/*) and OAuth2 server within the ActivityPub plugin, enabling Mastodon-compatible clients to connect to the Fedify-based server. Core features: - OAuth2 with PKCE (S256) — app registration, authorization, token exchange - Instance info + nodeinfo for client discovery - Account lookup, verification, relationships, follow/unfollow/mute/block - Home/public/hashtag timelines with cursor-based pagination - Status viewing, creation, deletion, thread context - Favourite, boost, bookmark interactions with AP federation - Notifications with type filtering and pagination - Search across accounts, statuses, and hashtags - Markers for read position tracking - Bookmarks and favourites collection lists - 25+ stub endpoints preventing client errors on unimplemented features Architecture: - 24 new files under lib/mastodon/ (entities, helpers, middleware, routes) - Virtual endpoint at "/" via Indiekit.addEndpoint() for domain-root access - CORS + JSON error handling for browser-based clients - Six-layer mute/block filtering reusing existing moderation infrastructure BREAKING CHANGE: bumps to v3.0.0 — adds new MongoDB collections (ap_oauth_apps, ap_oauth_tokens, ap_markers) and new route registrations Confab-Link: http://localhost:8080/sessions/5360e3f5-b3cc-4bf3-8c31-5448e2b23947
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
/**
|
|
* Error handling middleware for Mastodon Client API routes.
|
|
*
|
|
* Ensures all errors return JSON in Mastodon's expected format
|
|
* instead of HTML error pages that masto.js cannot parse.
|
|
*
|
|
* Standard format: { "error": "description" }
|
|
* OAuth format: { "error": "error_type", "error_description": "..." }
|
|
*/
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
export function errorHandler(err, req, res, _next) {
|
|
const status = err.status || err.statusCode || 500;
|
|
|
|
// OAuth errors use RFC 6749 format
|
|
if (err.oauthError) {
|
|
return res.status(status).json({
|
|
error: err.oauthError,
|
|
error_description: err.message || "An error occurred",
|
|
});
|
|
}
|
|
|
|
// Standard Mastodon error format
|
|
res.status(status).json({
|
|
error: err.message || "An unexpected error occurred",
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 501 catch-all for unimplemented API endpoints.
|
|
* Must be mounted AFTER all implemented routes.
|
|
*/
|
|
export function notImplementedHandler(req, res) {
|
|
res.status(501).json({
|
|
error: "Not implemented",
|
|
});
|
|
}
|