1
00:00:00,180 --> 00:00:05,250
All right, and once our aramid lawyer is able to handle our database errors.

2
00:00:05,910 --> 00:00:11,850
Now let's take a look at how we can check for both errors in the controller as well.

3
00:00:12,240 --> 00:00:14,340
And I'm talking about the registered controller, of course.

4
00:00:14,640 --> 00:00:21,750
First, it will make our API less error prone and second, in some cases checking for specific error

5
00:00:22,050 --> 00:00:25,260
in the controller before it hits the error middleware.

6
00:00:25,560 --> 00:00:31,440
It's actually quite useful, and it's my personal preference to use my error checking in the controller

7
00:00:31,590 --> 00:00:33,150
somewhat irregularly.

8
00:00:33,480 --> 00:00:39,420
Lastly, in the process, we'll also take a look at how we can set up custom or class.

9
00:00:39,570 --> 00:00:39,930
So.

10
00:00:40,810 --> 00:00:49,630
Let's get cracking by first navigating back to the off controller, and let's try to remember where

11
00:00:49,630 --> 00:00:54,490
the values are located, so they're located in the body, correct?

12
00:00:54,910 --> 00:00:56,140
So here's what I can do.

13
00:00:56,650 --> 00:01:01,720
I can just check for name in Maryland passport so I can pull them out.

14
00:01:01,720 --> 00:01:09,370
So name, email, comma and password and now set that one equal to a right down body.

15
00:01:10,060 --> 00:01:12,610
So we pull out the values and all we can do.

16
00:01:12,850 --> 00:01:14,710
We're going to check for empty values.

17
00:01:15,430 --> 00:01:25,720
I'm going to just say here your name is not provided or if email is not provided or if the password

18
00:01:25,720 --> 00:01:26,350
is not private.

19
00:01:26,560 --> 00:01:26,920
Correct.

20
00:01:27,400 --> 00:01:29,800
So if one of them is missing, what can we do?

21
00:01:30,250 --> 00:01:37,900
Well, remember, since we're using the package, the express async arrest package, instead of going

22
00:01:37,900 --> 00:01:46,280
next and passing in some kind of error when we need to do is go through new and for time being.

23
00:01:46,510 --> 00:01:49,360
We'll just rely on JavaScript error class.

24
00:01:49,750 --> 00:01:56,620
And again, if you're on a double check that just go back to the read me and let's click over here,

25
00:01:56,800 --> 00:01:58,240
let's navigate to their index.

26
00:01:58,750 --> 00:02:06,850
And once you get there as a refresher, remember, instead of going with next, we need to go through

27
00:02:07,180 --> 00:02:08,699
an error online.

28
00:02:08,710 --> 00:02:10,270
We pass in the error message.

29
00:02:10,509 --> 00:02:17,200
And this is coming from the JavaScript, and I'll probably mention that 20000 times in the following

30
00:02:17,200 --> 00:02:17,530
video.

31
00:02:17,590 --> 00:02:20,350
So we go with more and let's pass the message.

32
00:02:20,560 --> 00:02:26,250
Let's say please provide on values like show one.

33
00:02:27,100 --> 00:02:32,650
It also kind of makes sense that if we change the sound correct where instead of just passing it, everything

34
00:02:32,650 --> 00:02:39,910
that we're getting from that body, I'll specifically say that I want to pass a name, email and password.

35
00:02:40,070 --> 00:02:41,590
Mike, so let's save it.

36
00:02:42,070 --> 00:02:48,730
And before we can go any further, where we also need to do is go to the arrow handler.

37
00:02:49,210 --> 00:02:52,600
And now let's log specifically the message property.

38
00:02:53,430 --> 00:02:58,140
Because I want to showcase something, so instead of logging the entire object, I'm going to go with

39
00:02:58,140 --> 00:03:00,120
error and message.

40
00:03:00,360 --> 00:03:03,600
Now if you're wondering, how do I know that such message property exists?

41
00:03:04,420 --> 00:03:07,560
Oh, because we're using built in JavaScript error constructor.

42
00:03:08,440 --> 00:03:13,600
And if we take a look at the Indian ducks, we can say that it accepts a message as an argument.

43
00:03:14,110 --> 00:03:22,810
And just to demonstrate that I created a straight up vanilla jazz code where I create an object by invoking

44
00:03:22,810 --> 00:03:25,990
the Arrow Constructor and I passing the message.

45
00:03:26,440 --> 00:03:30,100
And once I logged erudite message, I get back the same value.

46
00:03:30,760 --> 00:03:36,610
Now, if you're wondering, which extension am I using to showcase the results straight up in my text

47
00:03:36,610 --> 00:03:39,370
that are the extension that is cue awkward.

48
00:03:39,370 --> 00:03:39,730
Yes?

49
00:03:39,970 --> 00:03:42,010
Now you don't have to buy a paid version.

50
00:03:42,250 --> 00:03:44,500
Essentially, there is a free version and a paid one.

51
00:03:44,830 --> 00:03:49,180
And as far as my use cases, I find the free version to be sufficient enough.

52
00:03:49,450 --> 00:03:54,890
So now let's head back to the postman and again, once remove the name, that probably is going to be

53
00:03:54,890 --> 00:03:55,390
the easiest.

54
00:03:55,840 --> 00:04:02,050
So let's send it here, and I'm getting back to five hundred and I still have something went wrong,

55
00:04:02,050 --> 00:04:04,270
so I do have the generic one.

56
00:04:04,270 --> 00:04:10,540
But let's take a look at the console and console over here says please provide all the values.

57
00:04:10,870 --> 00:04:13,210
Now, where is this coming from from here?

58
00:04:13,840 --> 00:04:15,700
Because this is the message that repression.

59
00:04:16,240 --> 00:04:23,470
So the first thing that we can do in order to set this up as 400 and then the actual message that we're

60
00:04:23,470 --> 00:04:29,020
passing in is in the era handler by setting up here the operator.

61
00:04:29,740 --> 00:04:34,630
So like I said in the beginning, it kind of looked useless, correct?

62
00:04:34,780 --> 00:04:37,330
Setting up this object, the default error.

63
00:04:37,660 --> 00:04:41,830
However, as we're adding more code, this looks very useful, correct?

64
00:04:42,160 --> 00:04:50,920
And now what I can do is say OK, if in the error that is being passed to this middleware, if there

65
00:04:50,920 --> 00:04:54,040
is already a message, then use that one.

66
00:04:54,490 --> 00:04:55,060
However.

67
00:04:56,050 --> 00:04:59,080
If there isn't one, then just go generic one.

68
00:04:59,710 --> 00:05:05,710
So the way that's going to look like we're going to go with air again, this is this error over here.

69
00:05:06,170 --> 00:05:09,310
Van, let's go with that message.

70
00:05:09,940 --> 00:05:12,610
And if it's present, then we'll go here.

71
00:05:12,880 --> 00:05:16,570
And if not, then we'll just go generic one.

72
00:05:16,900 --> 00:05:21,610
And remember, when it comes to the Mongols ones, we're overriding that anyway.

73
00:05:22,390 --> 00:05:24,940
So don't think about it too much.

74
00:05:25,300 --> 00:05:26,650
So let's go back over here.

75
00:05:26,920 --> 00:05:27,760
Let's Senate.

76
00:05:28,120 --> 00:05:28,810
And what?

77
00:05:29,050 --> 00:05:35,740
I still have five hundred fix that one in the following video, but not least, our message is custom.

78
00:05:36,250 --> 00:05:42,520
And what we're doing right now in the controller, we're actually checking for devices ourselves, which

79
00:05:42,520 --> 00:05:45,280
are going from time to time can be very useful.

