@@ -656,22 +656,16 @@ func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {
656656
657657 txn , err := transaction .NewTxnWithLocks (ctx , req .VolName , req .SnapName )
658658 if err != nil {
659- if err == transaction .ErrLockTimeout {
660- restutils .SendHTTPError (ctx , w , http .StatusConflict , err )
661- } else {
662- restutils .SendHTTPError (ctx , w , http .StatusInternalServerError , err )
663- }
659+ status , err := restutils .ErrToStatusCode (err )
660+ restutils .SendHTTPError (ctx , w , status , err )
664661 return
665662 }
666663 defer txn .Done ()
667664
668665 vol , e := volume .GetVolume (req .VolName )
669666 if e != nil {
670- if e == gderrors .ErrVolNotFound {
671- restutils .SendHTTPError (ctx , w , http .StatusNotFound , gderrors .ErrVolNotFound )
672- } else {
673- restutils .SendHTTPError (ctx , w , http .StatusInternalServerError , e )
674- }
667+ status , err := restutils .ErrToStatusCode (e )
668+ restutils .SendHTTPError (ctx , w , status , err )
675669 return
676670 }
677671
@@ -720,11 +714,8 @@ func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {
720714 err = txn .Do ()
721715 if err != nil {
722716 logger .WithError (err ).Error ("snapshot create transaction failed" )
723- if err == transaction .ErrLockTimeout {
724- restutils .SendHTTPError (ctx , w , http .StatusConflict , err )
725- } else {
726- restutils .SendHTTPError (ctx , w , http .StatusInternalServerError , err )
727- }
717+ status , err := restutils .ErrToStatusCode (err )
718+ restutils .SendHTTPError (ctx , w , status , err )
728719 return
729720 }
730721
0 commit comments