File tree 4 files changed +46
-0
lines changed
4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,17 @@ func (g Controller) GetNRandomMemes(c *gin.Context) {
40
40
// Remove Non Image posts from the Array
41
41
memes = utils .RemoveNonImagePosts (memes )
42
42
43
+ // Check if the Memes list has any posts
44
+ if len (memes ) == 0 {
45
+ response := response.Error {
46
+ Code : http .StatusInternalServerError ,
47
+ Message : "Error while getting Memes" ,
48
+ }
49
+
50
+ c .JSON (http .StatusInternalServerError , response )
51
+ return
52
+ }
53
+
43
54
// Get N no. of posts from that list
44
55
memes = utils .GetNRandomMemes (memes , count )
45
56
Original file line number Diff line number Diff line change 1
1
package gimme
2
2
3
3
import (
4
+ "fmt"
4
5
"net/http"
5
6
"strconv"
6
7
@@ -46,6 +47,17 @@ func (g Controller) GetNPostsFromSub(c *gin.Context) {
46
47
// Remove Non Image posts from the Array
47
48
memes = utils .RemoveNonImagePosts (memes )
48
49
50
+ // Check if the Memes list has any posts
51
+ if len (memes ) == 0 {
52
+ response := response.Error {
53
+ Code : http .StatusBadRequest ,
54
+ Message : fmt .Sprintf ("r/%s has no Posts with Images" , sub ),
55
+ }
56
+
57
+ c .JSON (http .StatusBadRequest , response )
58
+ return
59
+ }
60
+
49
61
// Get N no. of posts from that list
50
62
memes = utils .GetNRandomMemes (memes , count )
51
63
Original file line number Diff line number Diff line change 1
1
package gimme
2
2
3
3
import (
4
+ "fmt"
4
5
"net/http"
5
6
6
7
"github.com/R3l3ntl3ss/Meme_Api/controllers/utils"
@@ -30,6 +31,17 @@ func (g Controller) GetOnePostFromSub(c *gin.Context) {
30
31
// Remove Non Image posts from the Array
31
32
memes = utils .RemoveNonImagePosts (memes )
32
33
34
+ // Check if the Memes list has any posts
35
+ if len (memes ) == 0 {
36
+ response := response.Error {
37
+ Code : http .StatusBadRequest ,
38
+ Message : fmt .Sprintf ("r/%s has no Posts with Images" , sub ),
39
+ }
40
+
41
+ c .JSON (http .StatusBadRequest , response )
42
+ return
43
+ }
44
+
33
45
// Choose one post from the list
34
46
meme := memes [utils .GetRandomN (len (memes ))]
35
47
Original file line number Diff line number Diff line change @@ -33,6 +33,17 @@ func (g Controller) GetOneRandomMeme(c *gin.Context) {
33
33
// Remove Non Image posts from the Array
34
34
memes = utils .RemoveNonImagePosts (memes )
35
35
36
+ // Check if the Memes list has any posts
37
+ if len (memes ) == 0 {
38
+ response := response.Error {
39
+ Code : http .StatusInternalServerError ,
40
+ Message : "Error while getting Memes" ,
41
+ }
42
+
43
+ c .JSON (http .StatusInternalServerError , response )
44
+ return
45
+ }
46
+
36
47
// Choose one post from the list
37
48
meme := memes [utils .GetRandomN (len (memes ))]
38
49
You can’t perform that action at this time.
0 commit comments