WEBVTT

1
00:00:00.000 --> 00:00:00.130
each time would make our code pretty
long and unwieldy after a while.

2
00:00:00.130 --> 00:00:03.090
To get around this,
we can use a piece of middleware to wrap

3
00:00:03.090 --> 00:00:06.490
each of our routes automatically
in a try-catch block.

4
00:00:06.490 --> 00:00:10.440
That way we won't have to explicitly
write it over and over again.

5
00:00:10.440 --> 00:00:13.890
Let's write that middleware
at the top of our file.

6
00:00:13.890 --> 00:00:17.275
We'll name it asyncHandler and
it will take a callback.

7
00:00:23.727 --> 00:00:27.774
Inside the asyncHandler function we'll
return an asynchronous function that will

8
00:00:27.774 --> 00:00:29.775
serve as our route handler's callback.

9
00:00:29.775 --> 00:00:30.000
So it'll take the req,
res and next parameters.
