Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return 404 if didn't find an uuid #89

Merged
merged 3 commits into from
Sep 25, 2024

Conversation

HavierD
Copy link
Contributor

@HavierD HavierD commented Sep 25, 2024

No description provided.

@@ -39,7 +39,7 @@ public ResponseEntity<Collection> getCollection(String id, String sortBy) throws
return ResponseEntity.ok()
.body(StacToCollection.convert(model.getCollections().get(0)));
} else {
throw new NoSuchElementException(String.format("uuid %s not found!", id));
return ResponseEntity.notFound().build();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add more details to the returning message than simply 404 http status code?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test also failed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after double-checking, i found this function want to return: ResponseEntity<Colleciton>, so i can only set body whose type is a Collection. For not messing up this function, i think only 404 code is enough for this situation, because the client side knows the url and uuid.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so cannot do something like this?

return ResponseEntity.status(HttpStatus.NOT_FOUND).body(String.format("uuid %s not found!", id));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, having a log log.error(...); before returning 404 code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you don't have to make the controller method returning type using raw ResponseEntity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so cannot do something like this?

return ResponseEntity.status(HttpStatus.NOT_FOUND).body(String.format("uuid %s not found!", id));

yes this is what i tried, but it only want a Collection type for the body
image

So i use raw ResponseEntity before, not setting body for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please try, otherwise missing out what previously tried to inform.

the client side is ok, knows the uuid and the NOT_FOUND status. For the server side output, do you think adding a log.error() is ok?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, you can just print the log if too much hassles to deal with, I think the previous impl to get some traces for what happened should stay. I've seen animaltracking controllers always use raw ResponseEntity type for the method declaration.

@@ -39,7 +39,7 @@ public ResponseEntity<Collection> getCollection(String id, String sortBy) throws
return ResponseEntity.ok()
.body(StacToCollection.convert(model.getCollections().get(0)));
} else {
throw new NoSuchElementException(String.format("uuid %s not found!", id));
return ResponseEntity.notFound().build();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test also failed

@vietnguyengit vietnguyengit merged commit eee1d0c into main Sep 25, 2024
2 checks passed
@vietnguyengit vietnguyengit deleted the feature/5918-return-404-for-not-found-uuid branch September 25, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants