Skip to content

Commit b990670

Browse files
committed
feat: Handle "Artwork not found" error in GetArtwork handler
1 parent 124d4cb commit b990670

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

api/restful/routers/artwork/handlers.go

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ func GetArtwork(ctx *gin.Context) {
7070
artwork, err := service.GetArtworkByID(ctx, objectID)
7171
hasKey := ctx.GetBool("auth")
7272
if err != nil {
73+
if errors.Is(err, mongo.ErrNoDocuments) {
74+
ctx.JSON(http.StatusNotFound, &ArtworkResponse{
75+
Status: http.StatusNotFound,
76+
Message: "Artwork not found",
77+
})
78+
return
79+
}
7380
ctx.JSON(http.StatusInternalServerError, &ArtworkResponse{
7481
Status: http.StatusInternalServerError,
7582
Message: func() string {
@@ -79,6 +86,7 @@ func GetArtwork(ctx *gin.Context) {
7986
return "Failed to get artwork"
8087
}(),
8188
})
89+
return
8290
}
8391
if artwork == nil {
8492
ctx.JSON(http.StatusNotFound, &ArtworkResponse{

0 commit comments

Comments
 (0)