forked from TrueCloudLab/frostfs-s3-gw
[#217] Add errors for cors
Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
bbb6727054
commit
5b4b9df031
2 changed files with 23 additions and 3 deletions
|
@ -312,6 +312,10 @@ const (
|
|||
ErrAdminAccountNotEligible
|
||||
ErrServiceAccountNotFound
|
||||
ErrPostPolicyConditionInvalidFormat
|
||||
|
||||
//CORS configuration errors.
|
||||
ErrCORSUnsupportedMethod
|
||||
ErrCORSWildcardExposeHeaders
|
||||
)
|
||||
|
||||
// error code to Error structure, these fields carry respective
|
||||
|
@ -1909,6 +1913,18 @@ var errorCodes = errorCodeMap{
|
|||
Description: "Invalid according to Policy: Policy Condition failed",
|
||||
HTTPStatusCode: http.StatusForbidden,
|
||||
},
|
||||
ErrCORSUnsupportedMethod: {
|
||||
ErrCode: ErrCORSUnsupportedMethod,
|
||||
Code: "InvalidRequest",
|
||||
Description: "Found unsupported HTTP method in CORS config",
|
||||
HTTPStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
ErrCORSWildcardExposeHeaders: {
|
||||
ErrCode: ErrCORSWildcardExposeHeaders,
|
||||
Code: "InvalidRequest",
|
||||
Description: "ExposeHeader \"*\" contains wildcard. We currently do not support wildcard for ExposeHeader",
|
||||
HTTPStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
// Add your error structure here.
|
||||
}
|
||||
|
||||
|
@ -1945,6 +1961,11 @@ func GetAPIError(code ErrorCode) Error {
|
|||
return errorCodes.toAPIErr(ErrInternalError)
|
||||
}
|
||||
|
||||
// GetAPIErrorWithError provides API Error with additional error message for input API error code.
|
||||
func GetAPIErrorWithError(code ErrorCode, err error) Error {
|
||||
return errorCodes.toAPIErrWithErr(code, err)
|
||||
}
|
||||
|
||||
// ObjectError - error that linked to specific object.
|
||||
type ObjectError struct {
|
||||
Err error
|
||||
|
|
|
@ -262,13 +262,12 @@ func checkCORS(cors *CORSConfiguration) error {
|
|||
for _, r := range cors.CORSRules {
|
||||
for _, m := range r.AllowedMethods {
|
||||
if _, ok := supportedMethods[m]; !ok {
|
||||
return fmt.Errorf("unsupported HTTP method in CORS config %s", m)
|
||||
return errors.GetAPIErrorWithError(errors.ErrCORSUnsupportedMethod, fmt.Errorf("unsupported method is %s", m))
|
||||
}
|
||||
}
|
||||
for _, h := range r.ExposeHeaders {
|
||||
if h == wildcard {
|
||||
return fmt.Errorf("ExposeHeader \"*\" contains wildcard. We currently do not support wildcard " +
|
||||
"for ExposeHeader")
|
||||
return errors.GetAPIError(errors.ErrCORSWildcardExposeHeaders)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue