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

cosmosdb | Consistent StatusCodes.NotFound handling for Item.ts operations #23489

Open
nvictoros opened this issue Oct 12, 2022 · 2 comments
Open
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Milestone

Comments

@nvictoros
Copy link

nvictoros commented Oct 12, 2022

Is your feature request related to a problem? Please describe.

  • It is frustrating that read in Item.ts does not throw an error for StatusCodes.NotFound, but the other operations (e.g. delete) do. This is frustrating because:
    • it makes generic error handlers more complex than necessary
    • it is not documented anywhere that this is the case, which means you have to look at the code in this repo to understand why one does not throw an error and the others do
  • This difference in error handling for StatusCodes.NotFound is caused by this line where the error is caught and not thrown for read, and the error is instead is returned as the response.

Describe the solution you'd like

  • For read and the other operations to have a consistent way of handling errors from ClientContext, or at least just for StatusCodes.NotFound

Describe alternatives you've considered

  • Document this difference for the handling of StatusCodes.NotFound so that it is clear for developers

Additional context
Add any other context or screenshots about the feature request here.

require('dotenv').config();
const fs = require('fs');
const { CosmosClient } = require('@azure/cosmos');

const client = new CosmosClient({ endpoint: process.env.ENDPOINT, key: process.env.KEY });
const database = client.database(process.env.DATABASE);
const container = database.container(process.env.CONTAINER);

async function main() {
  console.log('Reading item');
  const item = await container.item('wrong-id').read();
  console.log('Item with wrong id resolved with status: ', item.statusCode);

  try {
    const deletedItem = await container.item('wrong-id').delete();
    console.log('Delete item resolved with status: ', deletedItem.statusCode);
  } catch (error) {
    console.error('Deleting item rejected with error: ', error);
  }
}

main()
  .then(() => { console.log('Exiting...'); process.exit(0); })
  .catch((error) => { console.error(error); process.exit(1); })
@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Oct 12, 2022
@azure-sdk azure-sdk added Client This issue points to a problem in the data-plane of the library. Cosmos needs-team-triage This issue needs the team to triage. labels Oct 12, 2022
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Oct 12, 2022
@xirzec xirzec removed the needs-team-triage This issue needs the team to triage. label Oct 12, 2022
@v1k1
Copy link
Member

v1k1 commented Jan 17, 2023

To honor back ward compatibility, we have decided to update documentation and make accept this behavior.

@gkan144
Copy link

gkan144 commented Jan 17, 2023

That is ok for now. But would it be possible to make the read and delete functionalities consistent in a future major version bump?

@xirzec xirzec added feature-request This issue requires a new behavior in the product in order be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Projects
None yet
Development

No branches or pull requests

8 participants