public static void HandleException(AbstractServerException exception, out ResponseEntity response) { if (Handler == null) { response = new ResponseEntity(exception); } else if (exception.GetType() == typeof(ServerEndpointNotValidException)) { var ex = (ServerEndpointNotValidException)exception; response = Handler.HandleEndpointNotValidException(ex); } else if (exception.GetType() == typeof(ServerRequestMethodNotSupportedException)) { var ex = (ServerRequestMethodNotSupportedException)exception; response = Handler.HandleServerRequestMethodNotSupportedException(ex); } else if (exception.GetType() == typeof(InternalServerErrorException)) { var ex = (InternalServerErrorException)exception; response = Handler.HandleInternalServerErrorException(ex); } else if (exception.GetType() == typeof(AbstractServerException)) { response = Handler.HandleAbstractServerException(exception); } else { response = new ResponseEntity(exception.Message); } }
/// <summary> /// Uses reflection to handle exceptions defined in a <see cref="SimpleServer.Attributes.ConfigAttribute" /> /// decorator. /// </summary> /// <param name="exception">An instance of a thrown <see cref="SimpleServer.Exceptions.AbstractServerException" /></param> /// <typeparam name="T">The implied Type of the Exception that extends /// <see cref="SimpleServer.Exceptions.AbstractServerException" /></typeparam> public static void HandleException(AbstractServerException exception, HttpListenerContext currentContext) { HandleException(exception, out ResponseEntity response); onError?.Invoke(exception); ContextRunner.SendResponse(response, currentContext); }