1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-24 13:48:49 +08:00

MF-1783 - Improve HTTP / gRPC codes when attempting to publish with nonexistent thing key / channel id (#1798)

* return 404 for non existent thing key or channel

Signed-off-by: SammyOina <sammyoina@gmail.com>

* check for malformed uuid input

Signed-off-by: SammyOina <sammyoina@gmail.com>

* use replace all

Signed-off-by: SammyOina <sammyoina@gmail.com>

* remove uuid check

Signed-off-by: SammyOina <sammyoina@gmail.com>

---------

Signed-off-by: SammyOina <sammyoina@gmail.com>
This commit is contained in:
Sammy Kerata Oina 2023-05-29 17:23:39 +03:00 committed by GitHub
parent acfa0aa7bb
commit da40c54141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -77,7 +77,7 @@ func parseSubtopic(subtopic string) (string, error) {
if err != nil {
return "", errMalformedSubtopic
}
subtopic = strings.Replace(subtopic, "/", ".", -1)
subtopic = strings.ReplaceAll(subtopic, "/", ".")
elems := strings.Split(subtopic, ".")
filteredElems := []string{}
@ -171,6 +171,9 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
w.WriteHeader(http.StatusForbidden)
case codes.Internal:
w.WriteHeader(http.StatusInternalServerError)
case codes.NotFound:
err = errors.ErrNotFound
w.WriteHeader(http.StatusNotFound)
default:
w.WriteHeader(http.StatusInternalServerError)
}

View File

@ -137,6 +137,9 @@ func encodeError(err error) error {
case errors.ErrNotFound:
return status.Error(codes.NotFound, "entity does not exist")
default:
if errors.Contains(err, errors.ErrNotFound) || errors.Contains(err, errors.ErrViewEntity) {
return status.Error(codes.NotFound, "entity does not exist")
}
return status.Error(codes.Internal, "internal server error")
}
}