@@ -869,7 +869,7 @@ func handleTestAws(w http.ResponseWriter, r *http.Request) {
869869 }
870870 ok , err := aws .IsValidLogin (awsConfig )
871871 if err != nil {
872- handleAwsError (w , err , "Unable to login. " )
872+ handleAwsError (w , err , awsOperationLogin )
873873 return
874874 }
875875 if ! ok {
@@ -880,7 +880,7 @@ func handleTestAws(w http.ResponseWriter, r *http.Request) {
880880 ok , err = aws .IsCorsCorrectlySet (awsConfig .Bucket , t .GokapiUrl )
881881 aws .LogOut ()
882882 if err != nil {
883- handleAwsError (w , err , "Could not get CORS settings. " )
883+ handleAwsError (w , err , awsOperationCors )
884884 return
885885 }
886886 if ! ok {
@@ -890,11 +890,24 @@ func handleTestAws(w http.ResponseWriter, r *http.Request) {
890890 _ , _ = w .Write ([]byte ("All tests OK." ))
891891}
892892
893- func handleAwsError (w http.ResponseWriter , err error , prefix string ) {
893+ const (
894+ awsOperationLogin = iota
895+ awsOperationCors
896+ )
897+
898+ func handleAwsError (w http.ResponseWriter , err error , operation int ) {
894899 var awsErr awserr.Error
895900 isAwsErr := errors .As (err , & awsErr )
901+ var prefix string
902+ switch operation {
903+ case awsOperationLogin :
904+ prefix = "Unable to login. "
905+ case awsOperationCors :
906+ prefix = "Could not get CORS settings. "
907+ }
896908 if isAwsErr {
897- switch awsErr .Code () {
909+ code := awsErr .Code ()
910+ switch code {
898911 case s3 .ErrCodeNoSuchBucket :
899912 _ , _ = w .Write ([]byte ("Invalid bucket or regions provided, bucket does not exist." ))
900913 case "Forbidden" :
@@ -903,6 +916,13 @@ func handleAwsError(w http.ResponseWriter, err error, prefix string) {
903916 _ , _ = w .Write ([]byte ("Unable to connect to server, check endpoint." ))
904917 case "SerializationError" :
905918 _ , _ = w .Write ([]byte ("Invalid response received by server, check endpoint." ))
919+ case "NotFound" :
920+ if operation == awsOperationCors {
921+ _ , _ = w .Write ([]byte ("Login OK, but could not check bucket CORS settings." ))
922+
923+ } else {
924+ _ , _ = w .Write ([]byte ("The requested resource could not be found, check endpoint" ))
925+ }
906926 default :
907927 _ , _ = w .Write ([]byte (prefix + "Error " + awsErr .Code () + ": " + err .Error ()))
908928 }
0 commit comments