better error handling
This commit is contained in:
parent
9e605e34b1
commit
3db31b6ddc
20
main.go
20
main.go
@ -109,15 +109,15 @@ func receiveChunk(c *gin.Context) {
|
|||||||
f, err := os.OpenFile(fmt.Sprintf("%s/%s", uploadFolder, c.GetHeader("file-name")), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
f, err := os.OpenFile(fmt.Sprintf("%s/%s", uploadFolder, c.GetHeader("file-name")), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, "")
|
c.JSON(http.StatusInternalServerError, "")
|
||||||
log.Fatal(err)
|
log.Panicf("receiveChunk: %v\n", err)
|
||||||
}
|
}
|
||||||
if _, err := f.Write(chunk); err != nil {
|
if _, err := f.Write(chunk); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, "")
|
c.JSON(http.StatusInternalServerError, "")
|
||||||
log.Fatal(err)
|
log.Panicf("receiveChunk: %v\n", err)
|
||||||
}
|
}
|
||||||
if err := f.Close(); err != nil {
|
if err := f.Close(); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, "")
|
c.JSON(http.StatusInternalServerError, "")
|
||||||
log.Fatal(err)
|
log.Panicf("receiveChunk: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, "Received chunk")
|
c.JSON(http.StatusOK, "Received chunk")
|
||||||
@ -136,9 +136,7 @@ func finishUpload(c *gin.Context) {
|
|||||||
log.Panicf("finishUpload: %v\n", err)
|
log.Panicf("finishUpload: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
allVideos := gin.H{}
|
c.JSON(http.StatusOK, "File uploaded successfully")
|
||||||
|
|
||||||
c.JSON(http.StatusOK, allVideos)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func listVideos(c *gin.Context) {
|
func listVideos(c *gin.Context) {
|
||||||
@ -186,7 +184,7 @@ func getVideo(c *gin.Context) {
|
|||||||
log.Panicf("getVideo: %v\n", err)
|
log.Panicf("getVideo: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteVideo(c *gin.Context) {
|
func deleteVideo(c *gin.Context) {
|
||||||
@ -200,16 +198,14 @@ func deleteVideo(c *gin.Context) {
|
|||||||
var filepath string
|
var filepath string
|
||||||
err = rows.Scan(&filepath)
|
err = rows.Scan(&filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("deleteVideo: %v\n", err)
|
|
||||||
c.JSON(http.StatusBadRequest, "Video does not exist")
|
c.JSON(http.StatusBadRequest, "Video does not exist")
|
||||||
return
|
log.Panicf("deleteVideo: %v\n", err)
|
||||||
}
|
}
|
||||||
fmt.Println(filepath)
|
fmt.Println(filepath)
|
||||||
err = rows.Err()
|
err = rows.Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, "")
|
||||||
log.Panicf("deleteVideo: %v\n", err)
|
log.Panicf("deleteVideo: %v\n", err)
|
||||||
c.JSON(http.StatusInternalServerError, "Scanning the row didn't work")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = dbpool.Exec(context.Background(), "delete from videos where id = $1", inputId)
|
_, err = dbpool.Exec(context.Background(), "delete from videos where id = $1", inputId)
|
||||||
@ -223,5 +219,5 @@ func deleteVideo(c *gin.Context) {
|
|||||||
log.Panicf("deleteVideo: %v\n", err)
|
log.Panicf("deleteVideo: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{}) // return list of videos
|
c.JSON(http.StatusOK, "File deleted successfully")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user