Skip to content

Instantly share code, notes, and snippets.

@Zfinix
Created January 8, 2023 13:26
Show Gist options
  • Save Zfinix/996972e5af779e4a9f6d96a2c48357a8 to your computer and use it in GitHub Desktop.
Save Zfinix/996972e5af779e4a9f6d96a2c48357a8 to your computer and use it in GitHub Desktop.
import 'dart:io';
import 'package:dart_frog/dart_frog.dart';
/// Handle Errors from Requests
Future<Response> requestHandler(
Future<Response?> Function() handler,
) async {
try {
return (await handler()) ?? Response.json(body: {});
} catch (e) {
return Response(
body: e.toString(),
statusCode: HttpStatus.internalServerError,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment