Let's get started working on our get handler.
We've already got some comments inside of you to guide us, but before we follow these comments too
closely, there's just one quick thing I want to mention about these first two steps.
We had said that we would first begin inside of here by checking to see if the file exists.
But there's kind of a slightly better way or a slightly faster way we can actually implement this step
rather than doing or starting off with a step to see if the file exists.
We can instead just try to directly read the file then if that process throws an error.
So we'll say if Reid throws and er we can inspect the ER.
And see if it says that the file.
Doesn't exist, and then obviously, if the file doesn't exist, we can create it and add in some default
cells.
The nice thing about this approach is that it allows us to just do one direct read to our hard drive
to decide whether or not that file exists.
So let's try taking a slightly different approach.
All right, I'm going to first begin by setting up a tri catch statement.
I'm going to inside of the tri statement itself, but in concert result is a weight first read file.
I'm going to try to read the file at Opeth.
And I'm going to specify the encoding of that file as well.
So then if we get something out of that file, we successfully read some results or some value out of
that, we can just go ahead and directly pass that in from Jason into an actual array of objects and
then send that back inside of a response.
So let's take care of that.
First, we'll do a resource.
Send Jason Pass with.
Result.
Otherwise, if we run into an error, let's go ahead and inspect the air and see if the air was thrown
because the file doesn't exist.
So for that, we're going to add in if error code equals equals equals E. no end.
So this is how we know that an error is thrown because the file doesn't exist.
We end up with a E no ent or which stands for error, no entity or that file does not exist.
So if that is the case, then inside of here we can eventually add in some code.
To create a file and add default cells.
Otherwise, we can go ahead and just read through the air, because that means that we've got some air
that we really did not anticipate, so we should probably throw it or something like that just to say,
hey, something really went wrong here.
In this case, I'll just read through the air.
All right, I'm going to clean up all these extra comments down here.
So this looks good for right now, we do, of course, have to add in some code right here to create
that file and add in some default cells.
We'll take care of that in just a moment.
Right now, let's save this.
We're going to go over to our REACT application in just a moment and start to add in some code to make
use of these two different route handlers that we have now set up.