chores: refactor struct and structure project
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RespondWithError(w http.ResponseWriter, r *http.Request, err error, msg string) {
|
||||
if err != nil {
|
||||
code := ErrUnauthorized.Code
|
||||
status := http.StatusUnauthorized
|
||||
|
||||
if errors.Is(err, ErrExpiryToken) {
|
||||
code = ErrExpiryToken.Code
|
||||
status = ErrExpiryToken.HttpCode
|
||||
}
|
||||
|
||||
RespondJsonErrorWithCode(r.Context(), w, err, code, status, msg)
|
||||
} else {
|
||||
RespondJsonErrorWithCode(r.Context(), w, nil,
|
||||
ErrUnauthorized.Code, http.StatusUnauthorized, msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user