Skip to content

Commit

Permalink
feat: request timeout for LDAP
Browse files Browse the repository at this point in the history
  • Loading branch information
Gobot1234 committed Apr 29, 2024
1 parent 8fd0918 commit 37f1d5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
15 changes: 7 additions & 8 deletions apps/anvil/src/ldap/ldap.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LdapUser } from "@/auth/interfaces/ldap-user.interface";
import { Injectable, Logger, OnModuleInit } from "@nestjs/common";
import * as ldap from "ldapjs";
import { LdapClass } from "@/ldap/ldap.class";
import { Injectable, Logger } from "@nestjs/common";

@Injectable()
export class LdapService {
Expand All @@ -21,7 +20,7 @@ export class LdapService {
const result = await this.ldapClass.lookupByUsername(username);
if (result) {
const user = this.formatLdapUser(result);
this.logger.log(`Found user by username ${username}:`, user);
this.logger.log(`Found user by username ${username}:`, LdapService.name);
return user;
}
this.logger.log(`User not found by username: ${username}`);
Expand All @@ -33,10 +32,10 @@ export class LdapService {
const result = await this.ldapClass.lookupByEmail(email);
if (result) {
const user = this.formatLdapUser(result);
this.logger.log(`Found user by email ${email}:`, user);
this.logger.log(`Found user by email ${email}:`, LdapService.name);
return user;
}
this.logger.log(`User not found by email: ${email}`);
this.logger.log(`User not found by email: ${email}`, LdapService.name);
return null;
}

Expand All @@ -45,15 +44,15 @@ export class LdapService {
const result = await this.ldapClass.lookupByUcardNumber(ucardNumber);
if (result) {
const user = this.formatLdapUser(result);
this.logger.log(`Found user by ucard number ${ucardNumber}:`, user);
this.logger.log(`Found user by ucard number ${ucardNumber}:`, LdapService.name);
return user;
}
this.logger.log(`User not found by ucard number: ${ucardNumber}`);
this.logger.log(`User not found by ucard number: ${ucardNumber}`, LdapService.name);
return null;
}

private formatLdapUser(result: Record<string, string | string[]>): LdapUser {
this.logger.log(`Formatting response ${JSON.stringify(result)}`);
this.logger.log(`Formatting response ${JSON.stringify(result)}`, LdapService.name);
return {
uid: result.uid as string,
sn: result.sn as string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const ToolSelectionInput: FlowStepComponent = ({ onSecondary, onPrimary }) => {
const { data, isLoading, error } = useQuery({
queryKey: ["getSignIn", signInProps],
queryFn: () => GetSignIn(signInProps),
retry: 1,
});

const handleOnTrainingSelect = (selectedTrainings: Training[]) => {
Expand Down
4 changes: 3 additions & 1 deletion apps/forge/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export function extractError(error: Error): string {
return undefined as never;
}
if (isAxiosError(error)) {
return `${ErrorCodes[error.response?.data.code] || "unspecified_error"}: ${error.response?.data.message}`;
return `${ErrorCodes[error.response?.data.code] || "unspecified_error"}: ${
error.response?.data.message || error.message || "Unknown Error. Contact the IT Team"
}`;
}
return error?.message || "Unknown Error. Contact the IT Team";
}
Expand Down
6 changes: 5 additions & 1 deletion apps/forge/src/services/signin/signInService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export interface GetSignInProps {

export const GetSignIn = async ({ locationName, uCardNumber, signal }: GetSignInProps): Promise<User> => {
try {
const { data } = await axiosInstance.get(`/location/${locationName}/sign-in/${uCardNumber}`, { signal: signal });
const { data } = await axiosInstance.get(`/location/${locationName}/sign-in/${uCardNumber}`, {
signal: signal,
timeout: 10_000,
timeoutErrorMessage: "Timed out waiting for the user's info.",
});
return data;
} catch (error) {
console.error("An error occurred while Getting Sign In:", error);
Expand Down

0 comments on commit 37f1d5d

Please sign in to comment.