-
Notifications
You must be signed in to change notification settings - Fork 345
fix: memory leaks, error handling, and validation bugs #1156
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1065,15 +1065,15 @@ export default class EmbeddedChatApi { | |||||||
| "description", | ||||||||
| fileDescription.length !== 0 ? fileDescription : "" | ||||||||
| ); | ||||||||
| const response = fetch(`${this.host}/api/v1/rooms.upload/${this.rid}`, { | ||||||||
| const response = await fetch(`${this.host}/api/v1/rooms.upload/${this.rid}`, { | ||||||||
| method: "POST", | ||||||||
| body: form, | ||||||||
| headers: { | ||||||||
| "X-Auth-Token": authToken, | ||||||||
| "X-User-Id": userId, | ||||||||
| }, | ||||||||
| }).then((r) => r.json()); | ||||||||
| return response; | ||||||||
| }); | ||||||||
| return await response.json(); | ||||||||
| } catch (err) { | ||||||||
| console.log(err); | ||||||||
| } | ||||||||
|
|
@@ -1121,7 +1121,7 @@ export default class EmbeddedChatApi { | |||||||
| try { | ||||||||
| const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; | ||||||||
| const response = await fetch( | ||||||||
| `${this.host}/api/v1/chat.search?roomId=${this.rid}&searchText=${text}`, | ||||||||
| `${this.host}/api/v1/chat.search?roomId=${this.rid}&searchText=${encodeURIComponent(text)}`, | ||||||||
| { | ||||||||
| headers: { | ||||||||
| "Content-Type": "application/json", | ||||||||
|
|
@@ -1188,17 +1188,20 @@ export default class EmbeddedChatApi { | |||||||
| } | ||||||||
|
|
||||||||
| async getCommandsList() { | ||||||||
| const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; | ||||||||
| const response = await fetch(`${this.host}/api/v1/commands.list`, { | ||||||||
| headers: { | ||||||||
| "Content-Type": "application/json", | ||||||||
| "X-Auth-Token": authToken, | ||||||||
| "X-User-Id": userId, | ||||||||
| }, | ||||||||
| method: "GET", | ||||||||
| }); | ||||||||
| const data = await response.json(); | ||||||||
| return data; | ||||||||
| try { | ||||||||
| const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; | ||||||||
| const response = await fetch(`${this.host}/api/v1/commands.list`, { | ||||||||
| headers: { | ||||||||
| "Content-Type": "application/json", | ||||||||
| "X-Auth-Token": authToken, | ||||||||
| "X-User-Id": userId, | ||||||||
| }, | ||||||||
| method: "GET", | ||||||||
| }); | ||||||||
| return await response.json(); | ||||||||
| } catch (err) { | ||||||||
| console.error(err); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| async execCommand({ | ||||||||
|
|
@@ -1210,74 +1213,86 @@ export default class EmbeddedChatApi { | |||||||
| params: string; | ||||||||
| tmid?: string; | ||||||||
| }) { | ||||||||
| const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; | ||||||||
| const response = await fetch(`${this.host}/api/v1/commands.run`, { | ||||||||
| headers: { | ||||||||
| "Content-Type": "application/json", | ||||||||
| "X-Auth-Token": authToken, | ||||||||
| "X-User-Id": userId, | ||||||||
| }, | ||||||||
| method: "POST", | ||||||||
| body: JSON.stringify({ | ||||||||
| command, | ||||||||
| params, | ||||||||
| tmid, | ||||||||
| roomId: this.rid, | ||||||||
| triggerId: Math.random().toString(32).slice(2, 20), | ||||||||
| }), | ||||||||
| }); | ||||||||
| const data = await response.json(); | ||||||||
| return data; | ||||||||
| } | ||||||||
|
|
||||||||
| async getUserStatus(reqUserId: string) { | ||||||||
| const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; | ||||||||
| const response = await fetch( | ||||||||
| `${this.host}/api/v1/users.getStatus?userId=${reqUserId}`, | ||||||||
| { | ||||||||
| method: "GET", | ||||||||
| try { | ||||||||
| const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; | ||||||||
| const response = await fetch(`${this.host}/api/v1/commands.run`, { | ||||||||
| headers: { | ||||||||
| "Content-Type": "application/json", | ||||||||
| "X-Auth-Token": authToken, | ||||||||
| "X-User-Id": userId, | ||||||||
| }, | ||||||||
| } | ||||||||
| ); | ||||||||
| const data = response.json(); | ||||||||
| return data; | ||||||||
| method: "POST", | ||||||||
| body: JSON.stringify({ | ||||||||
| command, | ||||||||
| params, | ||||||||
| tmid, | ||||||||
| roomId: this.rid, | ||||||||
| triggerId: Math.random().toString(32).slice(2, 20), | ||||||||
| }), | ||||||||
| }); | ||||||||
| return await response.json(); | ||||||||
| } catch (err) { | ||||||||
| console.error(err); | ||||||||
|
||||||||
| console.error(err); | |
| console.error(err); | |
| throw err; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,10 +33,14 @@ class RocketChatAuth { | |||||||||||||||||||||||
| * Add a callback that will be called when user login status changes | ||||||||||||||||||||||||
| * @param callback | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| async onAuthChange(callback: (user: object | null) => void) { | ||||||||||||||||||||||||
| onAuthChange(callback: (user: object | null) => void) { | ||||||||||||||||||||||||
| this.authListeners.push(callback); | ||||||||||||||||||||||||
| const user = await this.getCurrentUser(); | ||||||||||||||||||||||||
| callback(user); | ||||||||||||||||||||||||
| this.getCurrentUser().then((user) => { | ||||||||||||||||||||||||
| callback(user); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
Comment on lines
+38
to
+40
|
||||||||||||||||||||||||
| this.getCurrentUser().then((user) => { | |
| callback(user); | |
| }); | |
| this.getCurrentUser() | |
| .then((user) => { | |
| callback(user); | |
| }) | |
| .catch((error) => { | |
| console.error("Failed to fetch current user in onAuthChange:", error); | |
| callback(null); | |
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import ReportWindowButtons from './ReportWindowButtons'; | |
| import styles from './ReportMessage.styles'; | ||
|
|
||
| const MessageReportWindow = ({ messageId, message }) => { | ||
| const [reportDescription, setDescription] = useState(' '); | ||
| const [reportDescription, setDescription] = useState(''); | ||
| return ( | ||
|
Comment on lines
8
to
10
|
||
| <ReportWindowButtons | ||
| variant="danger" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCommandsListnow catches errors and only logs them, which resolves the promise asundefinedon failure. Callers expecting a response object (e.g., accessingdata.commands) will then throw a secondaryTypeError, and the original fetch error is effectively swallowed. Prefer rethrowing after logging or returning a consistent fallback shape so callers can handle failures predictably.