-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provicevk/unified responses #843
base: develop
Are you sure you want to change the base?
Conversation
SonarCloud Quality Gate failed. |
8fdf2a5
to
f6a4108
Compare
@@ -0,0 +1,23 @@ | |||
using Ardalis.SmartEnum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Excessive code) Is this using necessary?
@@ -0,0 +1,22 @@ | |||
using Ardalis.SmartEnum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Excessive code) Is this using necessary?
Message = message; | ||
} | ||
|
||
public static ApiErrorResponse Create(string groupName, string code, string message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain why instead of public ctor you have private ctor and public static? Statics are worser from testability point of view. As it does the same as ctor - what is the main reason to have it?
public class InputApiError : ApiError | ||
{ | ||
public static readonly InputApiError InputDataIncorrect | ||
= new (nameof(InputDataIncorrect), "Provided data input is incorrect"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Non-uniqueness) nameof
is a cool idea, but it will give you only method/prop name. Thus, in other class (i.e. child of this class named InputAdminApiError
) method/prop with same name (InputDataIncorrect
) could exist and you'll get eror-code collision if you forget to redefine GroupName
. Please use simple enum containing all error codes, or more complex schema ot generate them - at least
$"{nameof(class)}.{nameof(method or property)}"
Or even more complex approach could be used with CallerMemberNameAttribute and it's friends, if you like it
|
||
public sealed class ProviderApiError : ApiError | ||
{ | ||
public static readonly ProviderApiError ProviderNotCreated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment re nameof
and error codes
{ | ||
} | ||
|
||
public override string GroupName => nameof(InputApiError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Performance) Do you need this override? Why not set GroupName
in ctor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Related to all overiden GroupName
s)
|
||
public static class ApiErrorExtensions | ||
{ | ||
public static ApiErrorResponse CreateApiErrorResponse(this ApiError apiError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Code style) Consider necessity of this extension class.
Ususally extensions are good for code decoupling. Mapping extensions - when you have 2 classses not related to each other and you don't want introduce any hard dependency between them.
It is not the case for ApiError
and ApiErrorResponse
, as latter is direct child of former. So why not put this method in ApiErrorResponse
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably I don't get what problem you are fixing. Please explain why we need lot of inherited error types with no changes in data.
Are there any plans for extending logic or properties in future children?
Maybe it could be simpler? Like 1 class with lot of static properties for each api error code case, or simple enum, list of tuples (if you need that GroupName as separate thing), whatever?
Incoming:
Note that ApiError model should be used for 4xx, 5xx Http Codes.
All Api errors are introduced with a group and code. Therefore we use a dictionary of dictionaries in Frontend.
For future discussions:
BadRequest(ApiError error)
,NotFound(ApiError error)
that takesApiError
as parameter.For thinking:
return Err.WithMessage(ProviderApiError.ProviderNotCreated).WithCode(HttpStatusCode.BadRequest);