1 00:00:01,080 --> 00:00:05,430 The last video we established that we need to make sure that all of our different services respond to 2 00:00:05,430 --> 00:00:10,020 some invalid incoming data with a very similarly structured air response. 3 00:00:10,110 --> 00:00:14,400 So I'm not saying that should always be an array of objects but I'm saying I'm saying that we need to 4 00:00:14,400 --> 00:00:18,600 put some thought into this and make sure that we've got some consistent structure for every kind of 5 00:00:18,600 --> 00:00:23,610 air response we ever expect to send back from any service. 6 00:00:23,620 --> 00:00:25,880 Now I do want to clarify one quick thing. 7 00:00:25,990 --> 00:00:30,340 Right now we are really just talking about the case in which we send over some invalid data inside a 8 00:00:30,340 --> 00:00:32,980 request to one of our given services. 9 00:00:33,010 --> 00:00:36,580 So in other words we're really just talking about this scenario right now. 10 00:00:36,580 --> 00:00:42,610 So in scenario number one we're talking about sending some risk quest over to our art service with an 11 00:00:42,610 --> 00:00:47,040 e-mail of let's say gibberish that is clearly not an email. 12 00:00:47,050 --> 00:00:50,340 So at some point time we're going to run that email through express validator. 13 00:00:50,410 --> 00:00:53,860 And as soon as we do so boom something blows up we throw an error. 14 00:00:53,860 --> 00:00:58,870 We're not really throwing an error per say but we are an error state and we need to stop our request 15 00:00:58,870 --> 00:01:03,790 handler early and send back some kind of a response to whoever made this request. 16 00:01:03,790 --> 00:01:08,710 But again express validator is not the only thing that is going to be producing some kind of error that 17 00:01:08,710 --> 00:01:10,690 we need to send back to the user. 18 00:01:10,690 --> 00:01:16,230 There are many many other scenarios only an infinite number of other scenarios where you are going to 19 00:01:16,230 --> 00:01:21,790 opt to stop a request handler early and send back some kind of response and all these different responses 20 00:01:21,820 --> 00:01:25,390 no matter the source whether it's expressed validator or something else. 21 00:01:25,390 --> 00:01:29,750 We want to make sure that they all have this very identical structure. 22 00:01:29,750 --> 00:01:33,970 So let's start to think about some those other scenarios where something might go wrong and we will 23 00:01:33,970 --> 00:01:39,040 have to send back some kind response that we want to make sure it has this identical structure just 24 00:01:39,040 --> 00:01:42,560 so the react app can pass that error very easily. 25 00:01:42,580 --> 00:01:44,080 So here's another scenario right here. 26 00:01:44,080 --> 00:01:45,990 Let's consider scenario number two. 27 00:01:46,000 --> 00:01:50,310 Maybe we have some incoming requests with an email of test at test dot com. 28 00:01:50,410 --> 00:01:54,910 Well we get through that into express validator and express validator would say Well yeah that's a valid 29 00:01:54,910 --> 00:01:55,490 e-mail. 30 00:01:55,510 --> 00:01:57,140 Everything looks good. 31 00:01:57,220 --> 00:02:01,420 That would then go on to the next step of a request handler where we might check to see if that e-mail 32 00:02:01,420 --> 00:02:02,930 is already in use. 33 00:02:02,930 --> 00:02:07,210 And let's imagine that in this scenario maybe someone has already signed up with an e-mail up test at 34 00:02:07,210 --> 00:02:08,900 test dot com. 35 00:02:08,920 --> 00:02:13,840 So once we do this check right here we once again would probably throw some kind of error or we would 36 00:02:13,840 --> 00:02:18,100 need to throw or send an error back to whoever made this request. 37 00:02:18,100 --> 00:02:21,010 And so we've got the red X right there to indicate something went wrong. 38 00:02:21,010 --> 00:02:27,520 We need to send an error response back so in this case it is not express validator that is producing 39 00:02:27,520 --> 00:02:28,540 some kind of error. 40 00:02:28,540 --> 00:02:31,700 It is this totally unrelated chunk of code. 41 00:02:31,720 --> 00:02:37,300 So again we need to make sure that not only express validator knows how to send back a response of this 42 00:02:37,300 --> 00:02:41,950 structure right here we need to make sure that many other places inside of our code can send back an 43 00:02:41,950 --> 00:02:43,800 identical structure as well. 44 00:02:43,980 --> 00:02:45,130 Melissa even goes on from there. 45 00:02:45,160 --> 00:02:47,440 Let's consider scenario number three. 46 00:02:47,440 --> 00:02:52,030 So maybe with scenario number three we have an e mail test at test dot com. 47 00:02:52,210 --> 00:02:53,410 That is a valid e-mail. 48 00:02:53,440 --> 00:02:58,100 So it will get past express validator maybe in this case we're gonna check to see if the e-mail is already 49 00:02:58,110 --> 00:03:03,470 in use and maybe it's not maybe as an e-mail that we can sign up with and then maybe at that case we 50 00:03:03,490 --> 00:03:09,040 or in this case we just tried to sign up with a new user but for some reason maybe our database connection 51 00:03:09,040 --> 00:03:10,720 is down or something like that. 52 00:03:11,590 --> 00:03:15,730 So once again we have some kind of error that is going to be produced by our application and we need 53 00:03:15,730 --> 00:03:20,170 to somehow capture that error and send back some response to the user. 54 00:03:20,260 --> 00:03:24,270 Once again with a completely identical structure. 55 00:03:24,340 --> 00:03:29,470 So what I'm trying to say here in this series of diagrams is that we have no idea where something is 56 00:03:29,470 --> 00:03:31,570 going to go wrong inside of application. 57 00:03:31,720 --> 00:03:36,820 We might have something go wrong from Express validator and might go wrong during some kind of internal 58 00:03:36,820 --> 00:03:41,200 validation and it might go wrong even at the database access level. 59 00:03:41,410 --> 00:03:46,180 And in all these different scenarios we need to somehow capture these errors as they are occurring and 60 00:03:46,180 --> 00:03:50,840 sent back this identical looking structure no matter what. 61 00:03:51,010 --> 00:03:56,410 Because again we don't want our ReACT application to have to understand how to pass a billion of different 62 00:03:56,410 --> 00:03:57,160 kinds of errors. 63 00:03:57,160 --> 00:04:02,260 We just want to have this one identical structure that it will be used for absolutely everything that 64 00:04:02,260 --> 00:04:05,610 goes wrong inside of application OK. 65 00:04:05,640 --> 00:04:10,740 So now that we've got kind of a scope of this problem and we understand that we really need to have 66 00:04:10,740 --> 00:04:15,030 some robust area handling one more pause right here we're gonna start to investigate how we're going 67 00:04:15,030 --> 00:04:17,100 to implement all this using express.