You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When CORS fails, the current process always takes the same behavior as shown below, which is not applicable to a wide range of use cases.
Therefore, it would be easier to use if the following functions could be optionally set.
// ErrorHandler is a custom error handler function for handling CORS errors.// if you want to write success response or call next handler, return true.// If you want to terminate further processing, return false.ErrorHandlerfunc(w http.ResponseWriter, r*http.Request, corsCors, errerror) bool
We also suggest that you define your own error structure to identify the errors passed here.
// Error is an interface for CORS errors.typeErrorinterface {
CorsError()
}
// PreflightError is an interface for preflight errors.typePreflightErrorinterface {
PreflightCorsError()
}
// ActualRequestError is an interface for actual request errors.typeActualRequestErrorinterface {
ActualRequestCorsError()
}
// PreflightNotOptionMethodError is returned when the method is not allowed.typePreflightNotOptionMethodErrorstruct {
Methodstring
}
func (e*PreflightNotOptionMethodError) Error() string {
returnfmt.Sprintf("Preflight aborted: %s!=OPTIONS", e.Method)
}
// Is implements the Is method of the error interface.func (e*PreflightNotOptionMethodError) Is(targeterror) bool {
_, ok:=target.(*PreflightNotOptionMethodError)
returnok
}
// As implements the As method of the error interface.func (e*PreflightNotOptionMethodError) As(targetany) bool {
switchtarget.(type) {
case**PreflightNotOptionMethodError:
returntruedefault:
returnfalse
}
}
// PreflightCorsError implements the PreflightCorsError interface.func (e*PreflightNotOptionMethodError) PreflightCorsError() {}
// CorsError implements the CorsError interface.func (e*PreflightNotOptionMethodError) CorsError() {}
The above code is just an example, and we believe that the structure should be separated for each error that is currently possible as a failure.
The text was updated successfully, but these errors were encountered:
ablankz
added a commit
to ablankz/cors
that referenced
this issue
May 3, 2024
When CORS fails, the current process always takes the same behavior as shown below, which is not applicable to a wide range of use cases.
Therefore, it would be easier to use if the following functions could be optionally set.
We also suggest that you define your own error structure to identify the errors passed here.
The above code is just an example, and we believe that the structure should be separated for each error that is currently possible as a failure.
The text was updated successfully, but these errors were encountered: