You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
972 B

4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
  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. }