Skip to content

[BUG]: Incorrect 200 Response from /v1/workspace/{slug}/update Endpoint with Invalid Payload #2541

Open
@MrSimonC

Description

@MrSimonC

How are you running AnythingLLM?

Docker (remote machine)

What happened?

When calling the endpoint /v1/workspace/{slug}/update with a POST request and the following payload:

{
  "name": "Updated Workspace Name",
  "openAiHistory": null
}

the endpoint incorrectly returns a 200 status code with the following message:

{
  "workspace": null,
  "message": "\nInvalid `prisma.workspaces.update()` invocation:\n\n{\n  where: {\n    id: 17\n  },\n  data: {\n    name: \"basssis Updated Workspace Name\",\n+   openAiHistory: Int\n  }\n}\n\nArgument `openAiHistory` must not be null."
}

The response indicates an error in the prisma.workspaces.update() invocation due to the openAiHistory field being null, which is not allowed.

Additional Information:
This issue leads to confusion as the status code 200 OK suggests that the operation was successful, while the message indicates an error. Proper error handling is required to ensure the API behaves as expected.

Suggested Fix:

  • Validate the payload before attempting to update the workspace. If openAiHistory is null and not allowed, return a 400 Bad Request status code with a clear error message.
  • Alternatively, modify the update logic to ignore null values for fields where null is not allowed, and proceed with updating the other valid fields.

Are there known steps to reproduce?

Expected Behavior:

  • The endpoint should return an appropriate error code (e.g., 400 Bad Request) if the openAiHistory field is null and cannot be processed.
  • Alternatively, the API should ignore the null value for openAiHistory and update the workspace with the provided valid fields, returning a 200 status code only if the operation is successful.

Steps to Reproduce:

  1. Deploy the API using Docker.
  2. Send a POST request to /v1/workspace/{slug}/update with the following payload:
    {
      "name": "Updated Workspace Name",
      "openAiHistory": null
    }
  3. Observe the response status code and message.

Actual Response:

  • Status Code: 200 OK
  • Response Body:
    {
      "workspace": null,
      "message": "\nInvalid `prisma.workspaces.update()` invocation:\n\n{\n  where: {\n    id: 17\n  },\n  data: {\n    name: \"basssis Updated Workspace Name\",\n+   openAiHistory: Int\n  }\n}\n\nArgument `openAiHistory` must not be null."
    }

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions