1
00:00:00,180 --> 00:00:06,120
All right, and two things that I would like to emphasize are falling first, remember those errors

2
00:00:06,120 --> 00:00:13,590
that we were getting in a server when we're standing up, if conditions in JavaScript, if we don't

3
00:00:13,590 --> 00:00:18,930
explicitly return and of course, JavaScript just keeps reading the code.

4
00:00:19,260 --> 00:00:19,650
Correct.

5
00:00:19,950 --> 00:00:26,880
So if I'm going to admit that return, I'm actually going to get the server error where I send back

6
00:00:27,120 --> 00:00:33,780
one response and then Joske just keeps reading the code and then expresses confused expressions like,

7
00:00:33,780 --> 00:00:36,390
hey, wait a minute, I already sent back the response.

8
00:00:36,630 --> 00:00:38,110
So why you're sending another.

9
00:00:38,130 --> 00:00:41,610
Now, keep in mind that it is happening in the same request.

10
00:00:41,760 --> 00:00:47,890
So you cannot send basically two responses in the same request, one after another.

11
00:00:48,120 --> 00:00:51,590
Yeah, of course, you can send one based on conditions.

12
00:00:51,630 --> 00:00:55,320
For example, if there are no products, you send back one response.

13
00:00:55,560 --> 00:00:59,610
And if you can yield some products, then great, then you send the second one.

14
00:00:59,820 --> 00:01:05,099
But you cannot send both of them one after another in the same request.

15
00:01:05,400 --> 00:01:09,900
And if you want to see that error again in action, go to the query.

16
00:01:10,140 --> 00:01:14,700
You'll add a question mark here and we're going to go search.

17
00:01:14,940 --> 00:01:18,990
And again, it is equal to be for example, that is my value.

18
00:01:19,210 --> 00:01:21,300
That's the starting value that I'm looking for.

19
00:01:21,550 --> 00:01:26,490
And once I do that, Noticia, I'm getting back the success true and data.

20
00:01:26,670 --> 00:01:34,110
But again, I have this big fat error in my server and it says that headers after they are sent to the

21
00:01:34,110 --> 00:01:38,990
client so we can have only one response per request.

22
00:01:39,450 --> 00:01:42,800
And in order to avoid that, we just go with return.

23
00:01:42,820 --> 00:01:47,340
So always, always, when you're setting up the condition, make sure that you go with the return so

24
00:01:47,340 --> 00:01:50,310
that we are returning from our callback function.

25
00:01:50,550 --> 00:01:55,230
And when we set up over here now where you'll avoid those errors.

26
00:01:55,380 --> 00:01:58,170
Now, of course, in this case, there is no more code red.

27
00:01:58,440 --> 00:02:04,500
So, yeah, it is a better practice if you just put this return here, but you won't get the error since

28
00:02:05,010 --> 00:02:06,150
there's nothing after that.

29
00:02:06,390 --> 00:02:13,110
And one more thing that I would like to mention normally, you're not going to set up a separate one

30
00:02:13,320 --> 00:02:14,570
just for the query.

31
00:02:14,760 --> 00:02:18,960
Yeah, there might be some cases, maybe there's some API to do that.

32
00:02:19,260 --> 00:02:23,690
But normally, again, you can just add it to where you're getting a list.

33
00:02:24,090 --> 00:02:31,080
So basically, if there is a query, beautiful, you're maybe going to store that data, you are going

34
00:02:31,080 --> 00:02:35,040
to filter it, you're going to set up some pages or whatever.

35
00:02:35,340 --> 00:02:41,610
And if no query string parameters are there, then you send back the whole product.

36
00:02:41,880 --> 00:02:43,230
And if you take a look.

37
00:02:44,080 --> 00:02:50,980
Pretty much nothing stops me here from just changing the API and products, and the functionality is

38
00:02:50,980 --> 00:02:59,020
going to work where if there are some queries from Paramus present, beautiful, notice how we're filtering

39
00:02:59,440 --> 00:03:00,350
our product.

40
00:03:00,370 --> 00:03:04,530
If not, then I always send back the product anyway.

41
00:03:04,710 --> 00:03:11,020
And as you can see, those are just copies of the product that are coming from my data.

42
00:03:11,580 --> 00:03:13,210
Yes, hopefully that is clear.

43
00:03:13,610 --> 00:03:15,520
Now, let's move on to our next topic.

