mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-30 07:09:01 +08:00
32 lines
946 B
Go
32 lines
946 B
Go
package iamapi
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/aws/aws-sdk-go/service/iam"
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
"github.com/chrislusf/seaweedfs/weed/s3api/s3err"
|
|
"net/http"
|
|
)
|
|
|
|
func writeIamErrorResponse(w http.ResponseWriter, err error, object string, value string, msg error) {
|
|
errCode := err.Error()
|
|
errorResp := ErrorResponse{}
|
|
errorResp.Error.Type = "Sender"
|
|
errorResp.Error.Code = &errCode
|
|
if msg != nil {
|
|
errMsg := msg.Error()
|
|
errorResp.Error.Message = &errMsg
|
|
}
|
|
glog.Errorf("Response %+v", err)
|
|
switch errCode {
|
|
case iam.ErrCodeNoSuchEntityException:
|
|
msg := fmt.Sprintf("The %s with name %s cannot be found.", object, value)
|
|
errorResp.Error.Message = &msg
|
|
s3err.WriteXMLResponse(w, http.StatusNotFound, errorResp)
|
|
case iam.ErrCodeServiceFailureException:
|
|
s3err.WriteXMLResponse(w, http.StatusInternalServerError, errorResp)
|
|
default:
|
|
s3err.WriteXMLResponse(w, http.StatusInternalServerError, errorResp)
|
|
}
|
|
}
|