seaweedfs/weed/iamapi/iamapi_handlers.go

32 lines
972 B
Go
Raw Normal View History

2020-12-09 20:11:49 +08:00
package iamapi
import (
"fmt"
2021-06-11 12:50:21 +08:00
"github.com/aws/aws-sdk-go/service/iam"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
2021-06-11 12:50:21 +08:00
"net/http"
2020-12-09 20:11:49 +08:00
)
2021-11-01 09:02:08 +08:00
func writeIamErrorResponse(w http.ResponseWriter, r *http.Request, err error, object string, value string, msg error) {
2021-03-29 15:01:44 +08:00
errCode := err.Error()
errorResp := ErrorResponse{}
errorResp.Error.Type = "Sender"
errorResp.Error.Code = &errCode
2021-04-08 14:16:36 +08:00
if msg != nil {
errMsg := msg.Error()
errorResp.Error.Message = &errMsg
}
2021-04-06 16:43:08 +08:00
glog.Errorf("Response %+v", err)
2021-03-29 15:01:44 +08:00
switch errCode {
case iam.ErrCodeNoSuchEntityException:
msg := fmt.Sprintf("The %s with name %s cannot be found.", object, value)
errorResp.Error.Message = &msg
2021-11-01 09:02:08 +08:00
s3err.WriteXMLResponse(w, r, http.StatusNotFound, errorResp)
2021-04-08 14:16:36 +08:00
case iam.ErrCodeServiceFailureException:
2021-11-01 09:02:08 +08:00
s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, errorResp)
2021-03-29 15:01:44 +08:00
default:
2021-11-01 09:02:08 +08:00
s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, errorResp)
2020-12-09 20:11:49 +08:00
}
}