Created
January 8, 2023 13:26
-
-
Save Zfinix/996972e5af779e4a9f6d96a2c48357a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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