1
00:00:00,270 --> 00:00:08,700
Another library that I find very useful is the A.P. Status Codes, which sets up these status codes

2
00:00:08,710 --> 00:00:09,660
as constants.

3
00:00:10,020 --> 00:00:16,410
So instead of hard coding, we will import the constants from the library and then apply them in our

4
00:00:16,410 --> 00:00:16,950
responses.

5
00:00:17,340 --> 00:00:19,650
Now that is my personal preference.

6
00:00:19,650 --> 00:00:21,810
So technically, you don't have to do it.

7
00:00:22,290 --> 00:00:27,870
So if you still prefer just hard coding here, these number of hours, you can definitely do so.

8
00:00:27,880 --> 00:00:35,610
But since I'm going to add it to our application, therefore I'll go over the details and effectively,

9
00:00:36,030 --> 00:00:40,250
in my opinion, it provides more consistency in the long run.

10
00:00:40,260 --> 00:00:47,460
I have found that there's less bugs and it's also easier to read and manage the application.

11
00:00:47,790 --> 00:00:49,920
If you want to find out more info, here's the link.

12
00:00:50,810 --> 00:00:57,620
And again, the main idea has fallen where essentially you install a library app that is clear and then

13
00:00:57,620 --> 00:00:59,120
you import the constants.

14
00:00:59,660 --> 00:01:06,620
So for example, for your one, we would get created and then we would set it up in response.

15
00:01:06,860 --> 00:01:10,400
So again, that way, I don't need to remember the status codes.

16
00:01:10,790 --> 00:01:14,340
And it's easier for me to read when I'm looking at my code.

17
00:01:14,780 --> 00:01:18,140
I right away, I understand what the response is doing.

18
00:01:18,320 --> 00:01:21,140
Again, my preference, you don't have to do part.

19
00:01:21,140 --> 00:01:22,760
In my case, I will install it.

20
00:01:23,150 --> 00:01:24,740
So we start over here.

21
00:01:24,980 --> 00:01:33,470
We get the install command, which is also in Read Me Van Copy and paste the library online.

22
00:01:33,680 --> 00:01:35,270
I want to set it up in two places.

23
00:01:35,690 --> 00:01:39,680
I want to set up in the off controller as well as the air handler.

24
00:01:40,040 --> 00:01:47,930
And then at the very end we'll set up default are which at the moment might seem like a useless thing.

25
00:01:48,290 --> 00:01:53,030
But since we'll be setting up Mongo reserves in the following videos, we might as well knock it out

26
00:01:53,030 --> 00:01:53,510
right now.

27
00:01:53,840 --> 00:02:00,290
So let me go back and start up the server and line again.

28
00:02:00,710 --> 00:02:06,190
We're looking for low status codes, import from the library and online.

29
00:02:06,200 --> 00:02:07,460
We're looking for a constant.

30
00:02:08,150 --> 00:02:15,020
So where we have the response, we go with status online, for example, 400 we go status code, that's

31
00:02:15,020 --> 00:02:15,440
the import.

32
00:02:15,710 --> 00:02:16,880
And then OK.

33
00:02:17,150 --> 00:02:23,300
And again, you can read all the contents over here and which status code they reference.

34
00:02:23,750 --> 00:02:32,510
So if we go back looking for off controller and I'm going to go and import more than four status codes

35
00:02:32,720 --> 00:02:39,500
from and then of course, the library, the status codes and then instead of two on one, I'm going

36
00:02:39,500 --> 00:02:44,090
to go here with status codes, status and codes.

37
00:02:44,360 --> 00:02:46,940
And then that, OK, let's say that.

38
00:02:48,180 --> 00:02:54,330
And then once we have this in place now, let me go to my error handler and I want to do the same thing

39
00:02:54,840 --> 00:02:56,940
where essentially I'll be disappointment.

40
00:02:57,300 --> 00:02:59,760
Well, copy are very important here.

41
00:03:01,010 --> 00:03:09,140
And like I said, instead of just sending the response in this way, I'll set up the default error response.

42
00:03:09,530 --> 00:03:14,600
Essentially, an object with two properties a status quo property as well as the message.

43
00:03:15,050 --> 00:03:23,750
And again, like I said before the moment, it might seem like a useless thing brought in a few videos.

44
00:03:24,140 --> 00:03:27,110
When we add more code, you'll see why we're doing that.

45
00:03:27,530 --> 00:03:29,660
So let's start over here by creating the object.

46
00:03:29,660 --> 00:03:32,360
So default and error.

47
00:03:32,870 --> 00:03:35,810
If you want to add sponsor, you can definitely do so in my case.

48
00:03:36,140 --> 00:03:37,180
We're going to go with default.

49
00:03:37,200 --> 00:03:41,180
Are now still console.log error that still stays the same.

50
00:03:41,420 --> 00:03:45,340
And then, like I said, there's going to be two properties status code.

51
00:03:45,860 --> 00:03:52,400
And for the time being, I'm just going to go with status codes DOT online 4500, which is going to

52
00:03:52,400 --> 00:03:57,480
be our default error, which you're looking for is internal and then server error.

53
00:03:57,680 --> 00:04:02,360
And notice how they right away nicely suggest the constants for you.

54
00:04:02,630 --> 00:04:04,280
So that's the 501.

55
00:04:04,610 --> 00:04:07,130
And as far as the message, let's set up the property first.

56
00:04:07,610 --> 00:04:10,700
So let's say here message and that will be equal to a string.

57
00:04:10,700 --> 00:04:11,510
Something went wrong.

58
00:04:11,750 --> 00:04:12,680
Try again later.

59
00:04:13,190 --> 00:04:17,600
And now where I have that response, instead of setting this up as five hundred, we're going to go

60
00:04:17,600 --> 00:04:18,829
with default error.

61
00:04:19,339 --> 00:04:27,170
That's the object that and then the status code and eventually will do the same thing over here, where

62
00:04:27,170 --> 00:04:30,380
a message will be equal to a default error and message.

63
00:04:30,620 --> 00:04:36,770
But while we're still setting up the Marash errors, I actually want to send back default problems because

64
00:04:37,040 --> 00:04:40,760
it's going to be easier to manage that instead of the console.

65
00:04:41,390 --> 00:04:48,560
So that way we can right away get the full response in The Postman and I can clearly show you which

66
00:04:48,560 --> 00:04:49,760
properties we're looking for.

67
00:04:49,790 --> 00:04:55,190
So, yes, eventually this will be equal to default error and then the message.

68
00:04:55,490 --> 00:05:01,760
But for the time being, we'll still be sending back the error that we're getting as the first argument.

