Bad Request Exceptions – Nonrelational Databases in Azure
Bad Request Exceptions
Errors that return the HTTP 400 status code represent bad request exceptions where the application request contains invalid data or is missing required parameters. These errors are typically caused by the following issues:
- The missing the ID property error means that the JSON item that is being inserted is missing the required ID property. Specify the ID property with a string value as a part of the item to resolve this issue.
- The invalid partition key type error means that the partition key value is an invalid data type. Make sure the partition key is a string or a numeric value.
- The wrong partition key value error means the partition key value being passed in the request does not match the item value in the container. For example, if the partition key path is /Id, the item has a field called Id and has values that do not include the value that was provided in the query. To resolve this issue, make sure the value used in the query is a valid partition key value.
Unauthorized Requests
Unauthorized requests are represented by a 401 HTTP error code, happening when an application request is performing an action with an invalid key. The following is a list of potential causes for unauthorized requests:
- The key is regenerated and the application using the key does not follow best practices for key rotation. This issue can be resolved by rotating the primary key to the secondary key and then regenerating the primary key. More information on key regeneration and rotation can be found at https://docs.microsoft.com/en-us/azure/cosmos-db/secure-access-to-data?tabs=using-primary-key#key-rotation.
- The key is misconfigured or was not copied correctly. Simply recopy the primary key or rotate to the secondary key to resolve this issue.
- The application is using a read-only key when trying to perform write operations. Switch the key to a read-write key if the application should be authorized to create or delete data.
- The application is trying to access a container before the container has finished being created. This typically happens when a container is deleted and then re-created with the same name.