2020-12-09 12:11:49 +00:00
|
|
|
package iamapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-06-11 04:50:21 +00:00
|
|
|
"github.com/aws/aws-sdk-go/service/iam"
|
2020-12-09 12:11:49 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/s3api/s3err"
|
2021-06-11 04:50:21 +00:00
|
|
|
"net/http"
|
2020-12-09 12:11:49 +00:00
|
|
|
)
|
|
|
|
|
2021-11-01 01:02:08 +00:00
|
|
|
func writeIamErrorResponse(w http.ResponseWriter, r *http.Request, err error, object string, value string, msg error) {
|
2021-03-29 07:01:44 +00:00
|
|
|
errCode := err.Error()
|
|
|
|
errorResp := ErrorResponse{}
|
|
|
|
errorResp.Error.Type = "Sender"
|
|
|
|
errorResp.Error.Code = &errCode
|
2021-04-08 06:16:36 +00:00
|
|
|
if msg != nil {
|
|
|
|
errMsg := msg.Error()
|
|
|
|
errorResp.Error.Message = &errMsg
|
|
|
|
}
|
2021-04-06 08:43:08 +00:00
|
|
|
glog.Errorf("Response %+v", err)
|
2021-03-29 07:01:44 +00: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 01:02:08 +00:00
|
|
|
s3err.WriteXMLResponse(w, r, http.StatusNotFound, errorResp)
|
2021-04-08 06:16:36 +00:00
|
|
|
case iam.ErrCodeServiceFailureException:
|
2021-11-01 01:02:08 +00:00
|
|
|
s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, errorResp)
|
2021-03-29 07:01:44 +00:00
|
|
|
default:
|
2021-11-01 01:02:08 +00:00
|
|
|
s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, errorResp)
|
2020-12-09 12:11:49 +00:00
|
|
|
}
|
|
|
|
}
|