iamapi_handlers.go 972 B

12345678910111213141516171819202122232425262728293031
  1. package iamapi
  2. import (
  3. "fmt"
  4. "github.com/aws/aws-sdk-go/service/iam"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/s3api/s3err"
  7. "net/http"
  8. )
  9. func writeIamErrorResponse(w http.ResponseWriter, r *http.Request, err error, object string, value string, msg error) {
  10. errCode := err.Error()
  11. errorResp := ErrorResponse{}
  12. errorResp.Error.Type = "Sender"
  13. errorResp.Error.Code = &errCode
  14. if msg != nil {
  15. errMsg := msg.Error()
  16. errorResp.Error.Message = &errMsg
  17. }
  18. glog.Errorf("Response %+v", err)
  19. switch errCode {
  20. case iam.ErrCodeNoSuchEntityException:
  21. msg := fmt.Sprintf("The %s with name %s cannot be found.", object, value)
  22. errorResp.Error.Message = &msg
  23. s3err.WriteXMLResponse(w, r, http.StatusNotFound, errorResp)
  24. case iam.ErrCodeServiceFailureException:
  25. s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, errorResp)
  26. default:
  27. s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, errorResp)
  28. }
  29. }