mirror of
https://github.com/kataras/iris.git
synced 2026-01-05 19:27:05 +00:00
Former-commit-id: 2b48b9b912e9eb8f5f2c6d413907dbfdae857e08
This commit is contained in:
@@ -211,7 +211,6 @@ func DispatchFuncResult(ctx context.Context, errorHandler ErrorHandler, values [
|
||||
)
|
||||
|
||||
for _, v := range values {
|
||||
|
||||
// order of these checks matters
|
||||
// for example, first we need to check for status code,
|
||||
// secondly the string (for content type and content)...
|
||||
@@ -310,27 +309,46 @@ func DispatchFuncResult(ctx context.Context, errorHandler ErrorHandler, values [
|
||||
// it's raw content, get the latest
|
||||
content = value
|
||||
case compatibleErr:
|
||||
if value != nil { // it's always not nil but keep it here.
|
||||
if errorHandler != nil {
|
||||
errorHandler.HandleError(ctx, value)
|
||||
break
|
||||
}
|
||||
|
||||
err = value
|
||||
if statusCode < 400 {
|
||||
statusCode = DefaultErrStatusCode
|
||||
}
|
||||
break // break on first error, error should be in the end but we
|
||||
// need to know break the dispatcher if any error.
|
||||
// at the end; we don't want to write anything to the response if error is not nil.
|
||||
if value == nil || di.IsNil(v) {
|
||||
continue
|
||||
}
|
||||
|
||||
if errorHandler != nil {
|
||||
errorHandler.HandleError(ctx, value)
|
||||
break
|
||||
}
|
||||
|
||||
err = value
|
||||
if statusCode < 400 {
|
||||
statusCode = DefaultErrStatusCode
|
||||
}
|
||||
break // break on first error, error should be in the end but we
|
||||
// need to know break the dispatcher if any error.
|
||||
// at the end; we don't want to write anything to the response if error is not nil.
|
||||
|
||||
default:
|
||||
// else it's a custom struct or a dispatcher, we'll decide later
|
||||
// because content type and status code matters
|
||||
// do that check in order to be able to correctly dispatch:
|
||||
// (customStruct, error) -> customStruct filled and error is nil
|
||||
if custom == nil && f != nil {
|
||||
custom = f
|
||||
if custom == nil {
|
||||
// if it's a pointer to struct/map.
|
||||
|
||||
if di.IsNil(v) {
|
||||
// if just a ptr to struct with no content type given
|
||||
// then try to get the previous response writer's content type,
|
||||
// and if that is empty too then force-it to application/json
|
||||
// as the default content type we use for structs/maps.
|
||||
contentType = ctx.GetContentType()
|
||||
if contentType == "" {
|
||||
contentType = context.ContentJSONHeaderValue
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if value != nil {
|
||||
custom = value // content type will be take care later on.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user