Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/255 #257

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions controllers/rest/default_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ func DefaultWriteController(api Container, commandDispatcher model.CommandDispat
},
}
commandResponse, err = commandDispatcher.Dispatch(ctxt.Request().Context(), command, api, entityRepository, ctxt.Logger())
//an error handler `HTTPErrorHandler` can be defined on the echo instance to handle error responses
if err != nil {
if err.(*model.DomainError).Code == 400 {
return ctxt.JSON(http.StatusBadRequest, commandResponse)
}
return err
}

Expand All @@ -100,7 +98,12 @@ func DefaultWriteController(api Container, commandDispatcher model.CommandDispat
}
return ctxt.JSON(http.StatusCreated, commandResponse)
default:
return ctxt.JSON(http.StatusOK, commandResponse)
//check to see if the response is a map or string
if stringResponse, ok := commandResponse.(string); ok {
return ctxt.String(http.StatusOK, stringResponse)
} else {
return ctxt.JSON(http.StatusOK, commandResponse)
}
}
}
}
Expand Down