diff --git a/packages/pharaoh/lib/src/core.dart b/packages/pharaoh/lib/src/core.dart index 12201ed6..4c7cde49 100644 --- a/packages/pharaoh/lib/src/core.dart +++ b/packages/pharaoh/lib/src/core.dart @@ -22,8 +22,13 @@ import 'shelf_interop/shelf.dart' as shelf; part 'core_impl.dart'; +typedef PharaohError = ({Object exception, StackTrace trace}); + typedef OnErrorCallback = FutureOr Function( - Object error, Request req, Response res); + PharaohError error, + Request req, + Response res, +); abstract class Pharaoh implements RouterContract { factory Pharaoh() => $PharaohImpl(); diff --git a/packages/pharaoh/lib/src/core_impl.dart b/packages/pharaoh/lib/src/core_impl.dart index 48c4b8fc..6c464b9f 100644 --- a/packages/pharaoh/lib/src/core_impl.dart +++ b/packages/pharaoh/lib/src/core_impl.dart @@ -81,26 +81,28 @@ class $PharaohImpl extends RouterContract final request = Request.from(httpReq); final response = Response.create(); - - late ({Object error, StackTrace trace}) requestError; + late PharaohError requestError; try { final result = await resolveAndExecuteHandlers(request, response); return forward(httpReq, result.res); } catch (error, trace) { - requestError = (error: error, trace: trace); + requestError = (exception: error, trace: trace); } if (_onErrorCb == null) { - final status = requestError.error is SpannerRouteValidatorError + final status = requestError.exception is SpannerRouteValidatorError ? HttpStatus.unprocessableEntity : HttpStatus.internalServerError; return forward( httpReq, - response.json({ - 'error': requestError.error.toString(), - 'trace': requestError.trace.toString() - }, statusCode: status), + response.json( + { + 'error': requestError.exception.toString(), + 'trace': requestError.trace.toString() + }, + statusCode: status, + ), ); }