Angular and server side validation [closed]


Angular and server side validation [closed]



Is there some "best practice" to integrate Angular reactive forms with server side validation?
Searching, for now I found only



https://www.puzzle.ch/de/blog/articles/2017/01/18/server-side-validations-with-angular-2



EDIT



Not being able to answer myself this question, closed by some of Stackoverflow's overzealous users, I nevertheless suggest to look into the code generated by JHipster (CRUD code generator for Angular/Spring applications) for the case of a new entity with client and server side validation.



Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.





explain the downvote, please. Validating only client side is a secutirty risk: stackoverflow.com/questions/3531968/…
– John Donn
Jun 17 at 6:00





The downvotes are because you're asking for opinions (best practice) and off site resources (at least you suggest that by posting a link), both of which are off-topic.
– Ingo Bürk
Jun 17 at 6:26






If you want to discuss the goal and rules of the platform itself, that's a discussion you should take to meta. Question comments are definitely the wrong place for it. As far as the question goes: show example code, describe your thoughts and findings instead of dumping links and ask specific questions. Right now your question, to me, screams that you didn't care to put any effort in asking it which will drive many people away from answering it.
– Ingo Bürk
Jun 17 at 6:49





i think is just missunderstood, @JohnDonn have just ask how to integrate ServerSide validation answer inside Angular Reactive Form.. He don't ask opinion or what ever, just how to do this.
– Yanis-git
Jun 17 at 7:58




1 Answer
1



First i will clarify why we should integrate both client and server side validation for three main reasons :



Then about your question. include Server side validation error message on your reactive form looks to be great idea (especially for last reason above).



For that, as pruposed by your link, you should take adventage of HTTP status code who will help you to categorize your error type. Then you have to design generic ErrorResponseBag. For Example (and is just example easy to understand), MangoPay API have bellow schema for error reporting :


ErrorResponseBag


{
"resultCode" : 1234,
"ResultMessage" : "some message",
"MoreInformation" : "Optional extra information"
}



ResultCode : Is number who make reference to specific constant type error.



Then is easy to create EasyErrorHandler who intercept each HttpErrorResponse and put it on Alert or what ever.


EasyErrorHandler


HttpErrorResponse



Sample of HttpInterceptor in StackBlitz



source for mangopay



Note : if you need more information about HttpInterceptor file free to ask me

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

PHP contact form sending but not receiving emails