-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR makes SwaggerError type as the only type of Errors in API (removes our custom Error type) In additional: extend SwaggerError by Details field that contains some raw errors (like ent: something not found); move all error messages into 1 place and use these vars in handlers instead of strings; move some validations from repo to handlers (to generate errors properly); some updates in int tests: the most of error messages should be checked;
- Loading branch information
1 parent
c50c01f
commit b5b95cb
Showing
48 changed files
with
1,255 additions
and
790 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
package handlers | ||
|
||
import "git.epam.com/epm-lstr/epm-lstr-lc/be/internal/generated/swagger/models" | ||
import ( | ||
"net/http" | ||
|
||
func buildErrorPayload(err error) *models.Error { | ||
return &models.Error{ | ||
Data: &models.ErrorData{ | ||
Message: err.Error(), | ||
}, | ||
"git.epam.com/epm-lstr/epm-lstr-lc/be/internal/generated/swagger/models" | ||
) | ||
|
||
func buildErrorPayload(code int32, msg string, details string) *models.SwaggerError { | ||
return &models.SwaggerError{ | ||
Code: &code, | ||
Message: &msg, | ||
Details: details, // optional field for raw err messages | ||
} | ||
} | ||
|
||
func buildStringPayload(msg string) *models.Error { | ||
return &models.Error{ | ||
Data: &models.ErrorData{ | ||
Message: msg, | ||
}, | ||
} | ||
func buildInternalErrorPayload(msg string, details string) *models.SwaggerError { | ||
return buildErrorPayload(http.StatusInternalServerError, msg, details) | ||
} | ||
|
||
func buildExFailedErrorPayload(msg string, details string) *models.SwaggerError { | ||
return buildErrorPayload(http.StatusExpectationFailed, msg, details) | ||
} | ||
|
||
func buildConflictErrorPayload(msg string, details string) *models.SwaggerError { | ||
return buildErrorPayload(http.StatusConflict, msg, details) | ||
} | ||
|
||
func buildNotFoundErrorPayload(msg string, details string) *models.SwaggerError { | ||
return buildErrorPayload(http.StatusNotFound, msg, details) | ||
} | ||
|
||
func buildForbiddenErrorPayload(msg string, details string) *models.SwaggerError { | ||
return buildErrorPayload(http.StatusForbidden, msg, details) | ||
} | ||
|
||
func buildBadRequestErrorPayload(msg string, details string) *models.SwaggerError { | ||
return buildErrorPayload(http.StatusBadRequest, msg, details) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.