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:
parent
acfa0aa7bb
commit
da40c54141
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user