exceptions: handling errors in the Nest service layer

I would like to create a REST API with NestJs. But I want to add GraphQL as another higher level layer later. So, for starters, I have the basic layer controller, the service and the TypeORM repository. Suppose you want to update a user's username by id. The controller path could be

PATCH /users/:id/username

Two problems may arise in the service or repository layer:

  • User ID may not exist
  • Username already exist

The basic flow of this operation would be

  • Get the user by id
  • Handle error if the user does not exist
  • Check if the username already exists
  • Handle error if username already exists
  • Update the user's username

I'm thinking about how I should handle those mistakes. I could throw exceptions immediately based on this concept


NestJs provides some ready-to-use exceptions that I can use


The problem is that I don't think I should throw HTTP exceptions in my service layer. They must be thrown into the logic of my controller. So what is a common approach to those mistakes?

  • I must return? undefined instead of an updated user? The controller would not know which part failed.
  • Should I create my own exceptions by extending Error and throw them away?
  • Due to the fact that exceptions come with poor performance if the return type of the function is something like ?

Nest posts on the page and justify text

Recently I blogged again. I am currently using WordPress and I have some personal initiatives. For my life, I cannot understand how to include some publications in one of the initiatives, and other publications in the second initiative. At this time, everything is published on my home page.

Also, it seems that the new function & # 39; block & # 39; You have deleted the & # 39; justify text & # 39 ;. Is there any way to return this?

Can any of you kind souls help me?

html5: what are they for and why do they nest the DIV tag?

Much of this response is based on good practices, user experience, accessibility and my own opinion.

What is it

The div element does not have a special meaning Not at all Represent your children. It can be used with the class, langY title attributes to mark the semantics common to a group of consecutive elements.

Translation: "The element div It has no special meaning. Represent your children. It can be used with attributes class, lang Y title to mark the semantics common to a group of consecutive elements. "

Source of official W3C documentation https://www.w3.org/TR/2011/WD-html5-author-20110809/the-div-element.html

div = divThis is to divide the design into blocks. And, of course, you can receive CSS styles and receive the most diverse behaviors.

But why do they use so much?


I think we see so many divs in HTML because they are often misused, for example to build tables, menus and even forms … I will not generalize, but if you see in HTML an element that by breach uh block type and it's with the display set with display:inline It is probably being structurally misused.

I think in the next few years you will see less and less div, You know why? Because now HTML 5 is semantic. Now we can divide our design by , , , ,