1+ using Microsoft . AspNetCore . Http ;
2+
13namespace EntityInjector . Route . Exceptions ;
24
3- public class InternalServerErrorException ( string message ) : Exception ( message ) ;
5+ public abstract class RouteBindingException ( string message , Exception ? inner = null )
6+ : Exception ( message , inner )
7+ {
8+ public abstract int StatusCode { get ; }
9+ }
10+
11+ public sealed class RouteEntityNotFoundException ( string entityName , object ? id )
12+ : RouteBindingException ( $ "No { entityName } found for ID '{ id } '.")
13+ {
14+ public override int StatusCode => StatusCodes . Status404NotFound ;
15+
16+ public string EntityName { get ; } = entityName ;
17+ public object ? Id { get ; } = id ;
18+ }
19+
20+ public sealed class MissingRouteAttributeException ( string parameterName , string expectedAttribute )
21+ : RouteBindingException ( $ "Missing required { expectedAttribute } on action parameter '{ parameterName } '.")
22+ {
23+ public override int StatusCode => StatusCodes . Status400BadRequest ;
24+ }
25+
26+ public sealed class UnsupportedBindingTypeException ( Type targetType )
27+ : RouteBindingException ( $ "The type '{ targetType . Name } ' is not supported for route binding.")
28+ {
29+ public override int StatusCode => StatusCodes . Status400BadRequest ;
30+
31+ public Type TargetType { get ; } = targetType ;
32+ }
33+
34+ public sealed class BindingReceiverNotRegisteredException ( Type receiverType )
35+ : RouteBindingException ( $ "No binding receiver registered for type '{ receiverType . FullName } '.")
36+ {
37+ public override int StatusCode => StatusCodes . Status500InternalServerError ;
38+
39+ public Type ReceiverType { get ; } = receiverType ;
40+ }
41+
42+ public sealed class BindingReceiverContractException ( string methodName , Type receiverType )
43+ : RouteBindingException ( $ "Expected method '{ methodName } ' not found on receiver type '{ receiverType . Name } '.")
44+ {
45+ public override int StatusCode => StatusCodes . Status500InternalServerError ;
46+
47+ public string MethodName { get ; } = methodName ;
48+ public Type ReceiverType { get ; } = receiverType ;
49+ }
50+
51+ public sealed class UnexpectedBindingResultException ( Type expected , Type ? actual )
52+ : RouteBindingException ( $ "Expected result of type '{ expected . Name } ', but got '{ actual ? . Name ?? "null" } '.")
53+ {
54+ public override int StatusCode => StatusCodes . Status500InternalServerError ;
55+
56+ public Type ExpectedType { get ; } = expected ;
57+ public Type ? ActualType { get ; } = actual ;
58+ }
59+
60+ public sealed class MissingRouteParameterException ( string parameterName )
61+ : RouteBindingException ( $ "Route parameter '{ parameterName } ' was not found. Ensure it is correctly specified in the route.")
62+ {
63+ public override int StatusCode => StatusCodes . Status400BadRequest ;
64+
65+ public string ParameterName { get ; } = parameterName ;
66+ }
67+
68+ public sealed class InvalidRouteParameterFormatException ( string parameterName , Type expectedType , Type actualType )
69+ : RouteBindingException ( $ "Route parameter '{ parameterName } ' is of type '{ actualType . Name } ', but type '{ expectedType . Name } ' was expected.")
70+ {
71+ public override int StatusCode => StatusCodes . Status422UnprocessableEntity ;
72+
73+ public string ParameterName { get ; } = parameterName ;
74+ public Type ExpectedType { get ; } = expectedType ;
75+ public Type ActualType { get ; } = actualType ;
76+ }
77+
78+ public sealed class EmptyRouteSegmentListException ( string parameterName )
79+ : RouteBindingException ( $ "Route parameter '{ parameterName } ' did not contain any valid string segments.")
80+ {
81+ public override int StatusCode => StatusCodes . Status422UnprocessableEntity ;
482
5- public class NotFoundException( string message ) : Exception ( message ) ;
83+ public string ParameterName { get ; } = parameterName ;
84+ }
0 commit comments