fetch method
Performs the fetch operation.
Implementation
@override
Future<CloudflareResponse> fetch(CloudflareRequest request) async {
if (request.method.toUpperCase() != 'POST') {
return _error('method_not_allowed', 405);
}
try {
await _ensureSchema();
final pathSegments = Uri.parse(request.url).pathSegments;
final operation = pathSegments.isEmpty ? null : pathSegments.last;
if (operation == null || operation.isEmpty) {
return _error('operation_required', 400);
}
final decoded = await request.json<Object?>();
if (decoded is! Map) return _error('invalid_request', 400);
final payload = Map<String, Object?>.from(decoded);
return _dispatch(operation, payload);
} on FormatException {
return _error('invalid_request', 400);
} on ArgumentError {
return _error('invalid_request', 400);
} catch (error, stackTrace) {
// Keep platform diagnostics in Worker logs while never returning the
// exception text (which may contain deployment-specific details).
print('Cloudflare Durable Object store failure: $error\n$stackTrace');
return _error('store_unavailable', 500);
}
}