这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@timothycarambat
Copy link
Member

Pull Request Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

resolves #571

What is in this change?

Ability to fetch a single document in the documents folder regardless of its subfolder. Will return on first match as each document name is unique.

Additional Information

The document name is unique and should be a value found for name in the /v1/documents endpoint.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

@timothycarambat timothycarambat merged commit c61cbd1 into master Jan 16, 2024
@timothycarambat timothycarambat deleted the 571-document-by-id-api branch January 16, 2024 22:58
@review-agent-prime
Copy link

server/endpoints/api/document/index.js

Currently, the error messages are directly logged to the console and a generic 500 status code is sent to the client. This could potentially leak sensitive information to the client. It would be better to send a generic error message to the client and log the error details on the server side for debugging purposes.
Create Issue
See the diff
Checkout the fix

    try {
      const { docName } = request.params;
      const document = await findDocumentInDocuments(docName);
      if (!document) {
        response.sendStatus(404).end();
        return;
      }
      response.status(200).json({ document });
    } catch (e) {
      console.error(e);
      response.status(500).json({ error: 'An error occurred while processing your request.' }).end();
    }
git fetch origin && git checkout -b ReviewBot/Impro-swp4i7r origin/ReviewBot/Impro-swp4i7r

Comment on lines +180 to +191
try {
const { docName } = request.params;
const document = await findDocumentInDocuments(docName);
if (!document) {
response.sendStatus(404).end();
return;
}
response.status(200).json({ document });
} catch (e) {
console.log(e.message, e);
response.sendStatus(500).end();
}

Choose a reason for hiding this comment

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

The error handling has been improved by sending a generic error message to the client and logging the error details on the server side for debugging purposes.

Suggested change
try {
const { docName } = request.params;
const document = await findDocumentInDocuments(docName);
if (!document) {
response.sendStatus(404).end();
return;
}
response.status(200).json({ document });
} catch (e) {
console.log(e.message, e);
response.sendStatus(500).end();
}
try {
const { docName } = request.params;
const document = await findDocumentInDocuments(docName);
if (!document) {
response.sendStatus(404).end();
return;
}
response.status(200).json({ document });
} catch (e) {
console.error(e);
response.status(500).json({ error: 'An error occurred while processing your request.' }).end();
}

cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
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.

[FEAT]: Fetch single document by id endpoint

2 participants