Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- soID, err := ctr.Service.CreateServiceOutcome(document)
- if err != nil {
- elogerrors.LogErr(err, ctr.Logger)
- var dbErrors []DbError
- switch {
- case errors.Is(elogerrors.Cause(err), apiservice.ErrValidation):
- w.WriteHeader(http.StatusBadRequest)
- dbErrors = []DbError{{
- ErrId: 1,
- ErrMsg: string(elogerrors.PrintErr(err)),
- }}
- case errors.Is(elogerrors.Cause(err), apiservice.ErrServiceOutcomeAlreadyExists):
- w.WriteHeader(http.StatusBadRequest)
- dbErrors = []DbError{{
- ErrId: 2,
- ErrMsg: string(elogerrors.PrintErr(err)),
- }}
- default:
- var serviceOutcomeErrors apiservice.ServiceOutcomeErrors
- ok := errors.As(elogerrors.Cause(err), &serviceOutcomeErrors)
- if ok {
- w.WriteHeader(http.StatusBadRequest)
- dbErrors = make([]DbError, 0, len(serviceOutcomeErrors))
- for _, outcomeError := range serviceOutcomeErrors {
- dbError := DbError{
- ErrId: outcomeError.ErrId,
- ErrMsg: outcomeError.ErrMsg,
- }
- dbErrors = append(dbErrors, dbError)
- }
- break
- }
- w.WriteHeader(http.StatusInternalServerError)
- dbErrors = []DbError{{
- ErrId: 0,
- ErrMsg: string(elogerrors.PrintErr(err)),
- }}
- }
- dto := createErrorsDTO{dbErrors}
- err = json.NewEncoder(w).Encode(dto)
- if err != nil {
- elogerrors.LogErr(err, ctr.Logger)
- return
- }
- return
- }
Add Comment
Please, Sign In to add comment