fix: add AbortController and unmount guard to useIpLookup hook
- Add AbortController to cancel pending IP lookups when component unmounts - Prevent state updates on unmounted components by checking abort signal before setState calls - Add useEffect cleanup that aborts pending requests on unmount - Update lookupIp API function to accept optional AbortSignal parameter - Converts callback-based fetch to async/await pattern for better control flow - Aligns with other API functions that already support abort signals (fetchJails, fetchJailBannedIps) Fixes TASK-ABORT-04 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -237,11 +237,12 @@ export async function unbanAllBans(): Promise<UnbanAllResponse> {
|
||||
* Look up ban status and geo-location for an IP address.
|
||||
*
|
||||
* @param ip - IP address to look up.
|
||||
* @param signal - Optional abort signal for request cancellation.
|
||||
* @returns An {@link IpLookupResponse} with ban history and geo info.
|
||||
* @throws {ApiError} On non-2xx responses (400 for invalid IP).
|
||||
*/
|
||||
export async function lookupIp(ip: string): Promise<IpLookupResponse> {
|
||||
return get<IpLookupResponse>(ENDPOINTS.geoLookup(ip));
|
||||
export async function lookupIp(ip: string, signal?: AbortSignal): Promise<IpLookupResponse> {
|
||||
return get<IpLookupResponse>(ENDPOINTS.geoLookup(ip), signal);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user