RocketChat / RocketChat/EmbeddedChat
Refactor: Architectural cleanup of EmbeddedChatApi.ts
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 165
- Forks
- 381
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 1
Description
Description
The EmbeddedChatApi.ts file currently contains significant code duplication. Almost every API method (30+) manually retrieves the user session, constructs headers, stringifies JSON, and handles errors using redundant try/catch blocks.
Problems
-
High Redundancy: Construction of fetch options, manual
JSON.stringify, and repetitive error logging account for 30% of the file size (1200+ lines). Any change to the base request logic requires modification in dozens of places. -
Inconsistent Error Handling: Some methods log to
console.error, some toconsole.log, and others fail silently without clear error reporting to the caller. -
FormData Handling: Methods like
sendAttachmentrequire specific header handling (omitting Content-Type for the browser to set the boundary) which is currently handled as a one-off case.
Example
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(`${this.host}/api/v1/SOME_ENDPOINT`, {
headers: {
"Content-Type": "application/json",
"X-Auth-Token": authToken,
"X-User-Id": userId,
},
method: "GET/POST",
});
return await response.json();
} catch (err) {
console.error(err);
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading EmbeddedChatApi.ts and mapping the repeated session, header, request, and error-handling paths across its API methods. Inspect how callers depend on current responses and errors; done means common request handling is introduced without breaking FormData boundary handling or existing API behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100