Inside of our case, we now need to take a look at that incoming air, figure out exactly what went
wrong, and then print out some appropriate air message to the user.
So I'm going to show you a very quick example of how you might do this, but I'll leave it up to you
if you want to go through here and kind of put together some more exhaustive cases around handling this
error.
In other words, right now, we know for a hundred percent that one possible error is a port already
being in use.
So we'll add in some code to handle that case.
But there might be other kinds of errors that we just don't really know exist just yet.
And so I'm going to allow you to kind of figure out what those other kinds of errors might be.
So we'll put in just a very simple approach here, we'll say if your code is.
E atter in use, then let's go ahead and print up some appropriate air message to our user, then maybe
we'll do a console air of something like or is in use.
Try running on a different port.
And then going to delete the other console log.
And actually, let's bring that back.
And we'll just put in an else case, so like I said, we're only going to handle the one Distin situation
right now.
So if a port is in use, that's great, we'll tell you exactly what's going on.
Otherwise, if it's any other kind of area, we're going to tell them, hey, something went wrong.
We don't really know what figure out what's going on yourself.
Not great.
But again, I'm going to leave it up to you to kind of fix that up.
Now, the last thing we might want to do here, and this is kind of optional, kind of comes down to
some other topics are going to discuss a little bit later on around Seelie design.
But what we might also want to do inside of here is force an exit of our program is essentially we just
failed to start up our server and that was the entire point of running the server command.
So if we fail to start up our server, then we probably want to say, you know what, there's no point
in running our program anymore and we just want to forcibly exit.
So we might do a process, not exit one.
So this is going to forcibly exit our program with a status code of one, which pretty much just indicates
that we are exiting with an unsuccessful run of our program.
Let's say this again, back over a quick test.
I'll do another note, indexer, and now we're told there is a news.
Try running on a different port.
Very good.
And we get kicked back directly to our terminal.
The last thing we might do here to kind of enhance the user experience would be maybe tell the user
how to run on a different port because we're sure not telling them that right now.
So we might tell them to try to use the P command to run on a different port manually.
So it might say try to run on a different port.
And when you do add in, dash up on some other port, maybe in this case four thousand six.
And if we do that, then everything is going to run successfully.
OK, so this looks pretty good.
We've now got some reasonable error handling inside of here.
The very last thing I would like to do is if we do start up our search process successfully and we know
if we start listening for actual traffic, we should probably tell the user that, well, everything
is running successfully and how to now interact with our application.
You might notice that right now, if we put in that custom port and we start the server, there's no
message printed to the user whatsoever.
And so they might be really confused about what they're supposed to do right now.
So to handle that right after calling serve right here, we might decide to just put in a very quick
console log.
With a template string, notice the tactics and we could put in something like opened file name, that's
the name of the file that we just opened and we are reading cells from and maybe navigate to http localhost
ohlin.
And then port.
To edit the file.
So essentially just some directions that they need to open up their browser, go to that address if
they want to see that interface and start interacting with that list of cells, one little fix I need
to put inside of your is it needs to be option Stockport, not just port.
Now, if we save this and run it one last time, now we're giving the user some very clear instructions
so they could very easily copy that, take it over to the browser, see our react application appear
and start working round with that list of cells.
OK, so this looks pretty good, I think that we are pretty much all done with our Seelie, we've got
some pretty reasonable logic inside of here.
So we're going to take a pause right here, as usual, and back to the next video and continue work
on our local API.