1
00:00:01,160 --> 00:00:02,420
In this video.

2
00:00:02,420 --> 00:00:10,350
Let's go ahead and display the error messages in case one upon image or profile photo upload.

3
00:00:10,370 --> 00:00:12,650
So let's look at the possible error.

4
00:00:12,680 --> 00:00:19,230
One is, if a user refused to provide the image and the person clicked upload.

5
00:00:19,250 --> 00:00:20,400
Let's have a look.

6
00:00:20,420 --> 00:00:22,440
You can see that cannot read.

7
00:00:22,460 --> 00:00:25,520
Properties of undefined form path.

8
00:00:25,610 --> 00:00:30,780
And then the other possible error is that in case our server is down.

9
00:00:30,800 --> 00:00:34,850
So let's look at the controller for that users.

10
00:00:34,850 --> 00:00:39,290
And this is the upload profile photo controller.

11
00:00:39,560 --> 00:00:46,040
Before we go ahead and then make the request, let's check if a user is uploading a picture.

12
00:00:46,070 --> 00:00:56,710
So here I'm going to be asked, check if file exists and going to be as if on the red dot file.

13
00:00:56,720 --> 00:01:03,150
Meaning if we have a property on the file, then it means that the user is uploading a file.

14
00:01:03,170 --> 00:01:07,910
So let's convict this one to if there is no property on the file.

15
00:01:08,060 --> 00:01:12,260
So here we can return this kind of error like this for now.

16
00:01:12,260 --> 00:01:14,030
And let's have a look.

17
00:01:14,060 --> 00:01:15,710
Let's refresh it.

18
00:01:16,590 --> 00:01:18,330
And click on upload.

19
00:01:18,720 --> 00:01:25,710
You can see user not found, meaning that it's been called, but let me change this one to please.

20
00:01:27,180 --> 00:01:29,760
Upload image.

21
00:01:30,440 --> 00:01:34,430
Now let me refresh it and send again.

22
00:01:35,780 --> 00:01:41,540
You can see we have please upload image so we can make use of that to check.

23
00:01:41,750 --> 00:01:49,580
So instead of returning JSON data here we are going to render a template and pass this message into

24
00:01:49,580 --> 00:01:50,040
it.

25
00:01:50,060 --> 00:01:51,440
So here we go.

26
00:01:51,490 --> 00:01:59,770
I'm going to make use of red dot render and then I want to go to the profile template going to be uses

27
00:01:59,780 --> 00:02:07,760
for a slash profile, and I'm going to send error property and I will provide.

28
00:02:08,590 --> 00:02:11,710
Please provide image.

29
00:02:12,190 --> 00:02:12,550
All right.

30
00:02:12,550 --> 00:02:16,960
So let me remove this one and I'm good to go.

31
00:02:17,440 --> 00:02:20,590
So let's return from this function call.

32
00:02:20,980 --> 00:02:22,840
I'm going to copy this one.

33
00:02:22,840 --> 00:02:27,910
And in case there is no user, I also want to return this one.

34
00:02:27,910 --> 00:02:31,240
And I will say that user not found.

35
00:02:35,360 --> 00:02:36,260
Perfect.

36
00:02:36,380 --> 00:02:40,510
And then lastly, it's about this place here.

37
00:02:40,580 --> 00:02:42,710
The error message would be from the cloud.

38
00:02:42,750 --> 00:02:50,100
Nary So I'm going to paste this one here and for the message we are going to use this one as error dot

39
00:02:50,240 --> 00:02:50,990
message.

40
00:02:50,990 --> 00:02:53,330
So let me remove this one from here.

41
00:02:54,410 --> 00:03:03,290
Next step is that we are going to redirect the user to the profile page, so let's remove this one and

42
00:03:03,290 --> 00:03:05,420
make use of direct.

43
00:03:07,210 --> 00:03:09,010
And won't it be at risk?

44
00:03:09,040 --> 00:03:10,660
DOT Redirect.

45
00:03:10,990 --> 00:03:22,030
The endpoint is API for web slash version one users and then the profile dash page.

46
00:03:22,750 --> 00:03:27,070
For the meantime, I'm going to make a request without passing in the image.

47
00:03:27,070 --> 00:03:28,060
And let's see.

48
00:03:28,880 --> 00:03:33,050
You can see that is trying to send me to the profile page.

49
00:03:33,050 --> 00:03:38,030
So let's see how we can avoid that in case we have error.

50
00:03:38,030 --> 00:03:41,720
We don't want to send the user to the profile page by.

51
00:03:41,720 --> 00:03:49,550
Instead, we want to render the form for uploading and that is the upload profile photo.

52
00:03:49,550 --> 00:03:54,920
So let me copy the name and inside the controller.

53
00:03:54,920 --> 00:03:59,540
So here, if there is no file, I won't render that template.

54
00:03:59,540 --> 00:04:01,220
Likewise this.

55
00:04:01,640 --> 00:04:04,330
And then down here if you have an error.

56
00:04:06,150 --> 00:04:11,130
So let's refresh it and let's make the request.

57
00:04:12,180 --> 00:04:18,370
And you can see I'm still on the file form page, meaning that it worked.

58
00:04:18,390 --> 00:04:22,290
So let's go ahead and then display the actual error.

59
00:04:22,410 --> 00:04:25,820
So back to the upload photo templates.

60
00:04:25,830 --> 00:04:32,790
Let's cut this template for displaying the message and make use of if statement and better store to

61
00:04:32,790 --> 00:04:34,030
make our life easier.

62
00:04:34,050 --> 00:04:40,620
Let's come back to log in and then copy this error message as we did before.

63
00:04:40,620 --> 00:04:43,380
And I'm going to replace with this one.

64
00:04:44,580 --> 00:04:45,090
All right.

65
00:04:45,090 --> 00:04:48,870
So we are checking if we have an error, then we are going to use it.

66
00:04:49,950 --> 00:04:59,460
So save it and let me refresh it and hit send and you can see please upload profile image.

67
00:04:59,640 --> 00:05:03,630
If I upload, let's say this image.

68
00:05:03,660 --> 00:05:04,830
Let's have a look.

69
00:05:06,400 --> 00:05:12,730
And you can see that it has been redirected to the profile page with the updated image.

