1
00:00:00,000 --> 00:00:03,000
So we used this catch-all feature here,

2
00:00:03,000 --> 00:00:06,000
but currently there is one problem,

3
00:00:06,000 --> 00:00:07,000
if you wanna call it like this.

4
00:00:09,000 --> 00:00:12,000
Whenever we enter something invalid here,

5
00:00:12,000 --> 00:00:17,000
like too many POV segments, we see that fall back text.

6
00:00:17,000 --> 00:00:20,000
Now that's actually not necessarily a problem.

7
00:00:20,000 --> 00:00:22,000
We might be fine with that,

8
00:00:22,000 --> 00:00:27,000
but we also might want to actually show an error

9
00:00:27,000 --> 00:00:32,000
instead if invalid POV segments were entered here.

10
00:00:32,000 --> 00:00:34,000
and we could implement this

11
00:00:34,000 --> 00:00:37,000
by going back to the page.js file here.

12
00:00:37,000 --> 00:00:41,000
And then, right before returning this content,

13
00:00:41,000 --> 00:00:43,000
this JSX content, we could add a if check

14
00:00:43,000 --> 00:00:47,000
and check if we have a selected year

15
00:00:47,000 --> 00:00:51,000
and the available news years

16
00:00:51,000 --> 00:00:54,000
do not include this selected year.

17
00:00:54,000 --> 00:00:58,000
So the available news years will give us an array.

18
00:00:58,000 --> 00:01:01,000
Do not include the selected year,

19
00:01:01,000 --> 00:01:04,000
which we check by using the includes method

20
00:01:04,000 --> 00:01:06,000
and adding an exclamation mark in front of this.

21
00:01:09,000 --> 00:01:11,000
So now if we have a selected year,

22
00:01:11,000 --> 00:01:13,000
but it's not part of the available years,

23
00:01:15,000 --> 00:01:15,000
we'll make it into this if block.

24
00:01:15,000 --> 00:01:19,000
And in here, I want to throw a new error

25
00:01:19,000 --> 00:01:22,000
where I'll say "invalid filter."

26
00:01:24,000 --> 00:01:26,000
And that's not the only way of ending up

27
00:01:26,000 --> 00:01:28,000
with an invalid filter.

28
00:01:28,000 --> 00:01:29,000
Because besides this condition,

29
00:01:29,000 --> 00:01:32,000
there also is another alternative condition

30
00:01:32,000 --> 00:01:33,000
that should throw an error.

31
00:01:33,000 --> 00:01:35,000
So I'll add a logical or here

32
00:01:37,000 --> 00:01:40,000
and then I'll check if we maybe have a selected month

33
00:01:40,000 --> 00:01:44,000
and that selected month is not part of the available months.

34
00:01:45,000 --> 00:01:49,000
So if not get available news months

35
00:01:50,000 --> 00:01:54,000
and we have to pass the selected year to the news month,

36
00:01:55,000 --> 00:01:57,000
if that array does not include the selected month,

37
00:01:58,000 --> 00:02:00,000
that's the alternative condition.

38
00:02:02,000 --> 00:02:05,000
So if one of these two conditions,

39
00:02:05,000 --> 00:02:07,000
this condition or this condition,

40
00:02:07,000 --> 00:02:09,000
if one of these two conditions is met,

41
00:02:09,000 --> 00:02:11,000
we make it in there and throw an error.

42
00:02:12,000 --> 00:02:14,000
And actually here we have to be careful

43
00:02:14,000 --> 00:02:17,000
because the years and months,

44
00:02:17,000 --> 00:02:21,000
these utility functions will return,

45
00:02:21,000 --> 00:02:23,000
will actually be of type number.

46
00:02:23,000 --> 00:02:25,000
So we'll get back numbers here.

47
00:02:26,000 --> 00:02:28,000
Whereas the selected years

48
00:02:28,000 --> 00:02:31,000
and months which we extract from the path,

49
00:02:31,000 --> 00:02:34,000
the URL path will be of type string.

50
00:02:34,000 --> 00:02:37,000
Here it says any. but it will be strings.

51
00:02:37,000 --> 00:02:41,000
And includes therefore would actually return false

52
00:02:41,000 --> 00:02:43,000
since we have a type mismatch,

53
00:02:43,000 --> 00:02:46,000
even if it's the same kind of value that's stored.

54
00:02:47,000 --> 00:02:51,000
So we should actually convert selected year to a number here

55
00:02:51,000 --> 00:02:53,000
and also selected month here

56
00:02:53,000 --> 00:02:58,000
to make sure that we don't get an error in situations

57
00:02:58,000 --> 00:02:59,000
where we shouldn't get it.

58
00:03:01,000 --> 00:03:04,000
But with those changes made, you'll see that if you visit,

59
00:03:04,000 --> 00:03:07,000
for example, a valid year, that works.

60
00:03:07,000 --> 00:03:10,000
If you visit a valid year-month combination, that works.

61
00:03:10,000 --> 00:03:12,000
But if I enter invalid month,

62
00:03:12,000 --> 00:03:17,000
I get this default development mode error overlay.

63
00:03:17,000 --> 00:03:20,000
And if I enter some arbitrary paths,

64
00:03:20,000 --> 00:03:23,000
potentially also too many POV segments,

65
00:03:23,000 --> 00:03:26,000
I also get this error overlay.

66
00:03:27,000 --> 00:03:28,000
Now of course,

67
00:03:28,000 --> 00:03:30,000
I don't want to get that development error overlay,

68
00:03:30,000 --> 00:03:32,000
but instead my own error page

69
00:03:32,000 --> 00:03:36,000
and therefore, we should now also add error handling here.

