1
00:00:00,960 --> 00:00:03,330
Let's get started working on our get handler.

2
00:00:03,840 --> 00:00:08,010
We've already got some comments inside of you to guide us, but before we follow these comments too

3
00:00:08,010 --> 00:00:11,400
closely, there's just one quick thing I want to mention about these first two steps.

4
00:00:11,880 --> 00:00:15,510
We had said that we would first begin inside of here by checking to see if the file exists.

5
00:00:15,840 --> 00:00:20,430
But there's kind of a slightly better way or a slightly faster way we can actually implement this step

6
00:00:21,000 --> 00:00:24,390
rather than doing or starting off with a step to see if the file exists.

7
00:00:24,540 --> 00:00:32,009
We can instead just try to directly read the file then if that process throws an error.

8
00:00:33,200 --> 00:00:38,300
So we'll say if Reid throws and er we can inspect the ER.

9
00:00:39,270 --> 00:00:41,460
And see if it says that the file.

10
00:00:42,930 --> 00:00:47,670
Doesn't exist, and then obviously, if the file doesn't exist, we can create it and add in some default

11
00:00:47,670 --> 00:00:48,140
cells.

12
00:00:48,540 --> 00:00:53,250
The nice thing about this approach is that it allows us to just do one direct read to our hard drive

13
00:00:53,250 --> 00:00:55,290
to decide whether or not that file exists.

14
00:00:56,780 --> 00:00:58,630
So let's try taking a slightly different approach.

15
00:01:00,180 --> 00:01:03,180
All right, I'm going to first begin by setting up a tri catch statement.

16
00:01:08,190 --> 00:01:14,980
I'm going to inside of the tri statement itself, but in concert result is a weight first read file.

17
00:01:15,750 --> 00:01:18,180
I'm going to try to read the file at Opeth.

18
00:01:20,780 --> 00:01:23,530
And I'm going to specify the encoding of that file as well.

19
00:01:29,670 --> 00:01:34,770
So then if we get something out of that file, we successfully read some results or some value out of

20
00:01:34,770 --> 00:01:40,920
that, we can just go ahead and directly pass that in from Jason into an actual array of objects and

21
00:01:40,920 --> 00:01:42,770
then send that back inside of a response.

22
00:01:43,230 --> 00:01:43,980
So let's take care of that.

23
00:01:43,980 --> 00:01:46,380
First, we'll do a resource.

24
00:01:46,560 --> 00:01:50,130
Send Jason Pass with.

25
00:01:51,180 --> 00:01:51,750
Result.

26
00:01:54,930 --> 00:02:00,420
Otherwise, if we run into an error, let's go ahead and inspect the air and see if the air was thrown

27
00:02:00,450 --> 00:02:01,770
because the file doesn't exist.

28
00:02:02,190 --> 00:02:09,449
So for that, we're going to add in if error code equals equals equals E. no end.

29
00:02:10,169 --> 00:02:13,800
So this is how we know that an error is thrown because the file doesn't exist.

30
00:02:13,980 --> 00:02:19,830
We end up with a E no ent or which stands for error, no entity or that file does not exist.

31
00:02:20,630 --> 00:02:24,180
So if that is the case, then inside of here we can eventually add in some code.

32
00:02:26,980 --> 00:02:32,500
To create a file and add default cells.

33
00:02:33,940 --> 00:02:38,380
Otherwise, we can go ahead and just read through the air, because that means that we've got some air

34
00:02:38,380 --> 00:02:42,540
that we really did not anticipate, so we should probably throw it or something like that just to say,

35
00:02:42,540 --> 00:02:44,050
hey, something really went wrong here.

36
00:02:44,430 --> 00:02:46,000
In this case, I'll just read through the air.

37
00:02:49,250 --> 00:02:51,470
All right, I'm going to clean up all these extra comments down here.

38
00:02:53,780 --> 00:02:58,130
So this looks good for right now, we do, of course, have to add in some code right here to create

39
00:02:58,130 --> 00:02:59,840
that file and add in some default cells.

40
00:03:00,080 --> 00:03:01,520
We'll take care of that in just a moment.

41
00:03:01,970 --> 00:03:03,230
Right now, let's save this.

42
00:03:03,510 --> 00:03:08,270
We're going to go over to our REACT application in just a moment and start to add in some code to make

43
00:03:08,270 --> 00:03:10,850
use of these two different route handlers that we have now set up.

