Skip to content

Commit

Permalink
[ECO-5184] chore: use internal logger in react-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Jan 22, 2025
1 parent fdf0fb5 commit daff402
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/platform/react-hooks/src/hooks/useChannelAttach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
import { useConnectionStateListener } from './useConnectionStateListener.js';
import { useAbly } from './useAbly.js';
import { INACTIVE_CONNECTION_STATES } from './constants.js';
import { logError } from '../utils.js';

interface ChannelAttachResult {
connectionState: Ably.ConnectionState;
Expand Down Expand Up @@ -35,7 +36,7 @@ export function useChannelAttach(
channel.attach().catch((reason) => {
// we use a fire-and-forget approach for attaching, but calling detach during the attaching process or while
// suspending can cause errors that will be automatically resolved
console.log(reason);
logError(ably, reason.toString());
});
}
}, [shouldAttachToTheChannel, channel]);

Check warning on line 42 in src/platform/react-hooks/src/hooks/useChannelAttach.ts

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'ably'. Either include it or remove the dependency array
Expand Down
14 changes: 14 additions & 0 deletions src/platform/react-hooks/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* In rare cases when we need to access core logger to log error messages
*
* @param ablyClient ably core SDK client, it has any type because we access internal Logger class
* @param message message to log
*/
export const logError = (ablyClient: any, message: string) => {
try {
ablyClient.Logger.logAction(ablyClient.logger, ablyClient.Logger.LOG_ERROR, `[react-hooks] ${message}`);
} catch (error) {
// we don't want to fail on logger if something change
console.error(`Unable to access ably-js logger, while sending ${message}`);
}
};

0 comments on commit daff402

Please sign in to comment.