Skip to content

Add exception to core.get to handle index_not_found & document not found #2156

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

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion output/schema/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions specification/_global/get/GetResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@
*/

import { GetResult } from '@global/get/types'
import { ErrorResponseBase } from '@_types/Base'

export class Response<TDocument> {
body: GetResult<TDocument>
exceptions: [
{
// Special case exception for 404 status code, Elasticsearch will return either:
// * index_not_found_exception as an error if the index doesn't exist
// * GetResult with only the requested _id, _index properties and found as a false boolean
statusCodes: [404]
body: GetResult<TDocument> | ErrorResponseBase
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment explaining that ErrorResponseBase will be returned if the index doesn't exist, and GetResult if the id doesn't exist, and in that case it will only contain "found": false, _id and _index?

And for the sake of nitpicking flip the two members of the union: start with the result for the unknown index and finish with the result for the unknown id 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Documentation added!

The order is consistent with the existing exceptions in the rest of the specification; I suggest we keep it that way.

}
]
}