Skip to content

Commit

Permalink
Return exception on device registration failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmoy12c committed Dec 4, 2023
1 parent f083df1 commit d30a956
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/modules/user-segment/fusionauth/fusionauth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FusionAuthClient, {
} from '@fusionauth/typescript-client';

import ClientResponse from '@fusionauth/typescript-client/build/src/ClientResponse';
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { Injectable, InternalServerErrorException, Logger, ServiceUnavailableException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { retryPromiseWithDelay } from '../../../common/retry';
import { FusionAuthClientProvider } from './fusionauthClientProvider';
Expand Down Expand Up @@ -174,7 +174,7 @@ export class DeviceManagerService {

return await retryPromiseWithDelay(
() => this.client.register("", userRequestJSON),
2,
3,
2000
)
.then((response: ClientResponse<RegistrationResponse>) => {
Expand All @@ -186,14 +186,10 @@ export class DeviceManagerService {
.catch((e: Error) => {
this.logger.error(
`Error Registering Device in Registry: BotId - ${botId}, device - ${deviceString}. Error: ${JSON.stringify(
e.message,
e,
)}`,
);
return {
userId: null,
status: FAStatus.ERROR,
error: e.message,
};
throw new ServiceUnavailableException("Could not add device to registry!");
});
} else {
//Register user to existing bot
Expand All @@ -217,7 +213,7 @@ export class DeviceManagerService {
applicationId: botId,
},
}),
2,
3,
2000
)
.then((response) => {
Expand All @@ -231,13 +227,9 @@ export class DeviceManagerService {
})
.catch((e) => {
this.logger.error(
`Error Registering Device in Registry: BotId - ${botId}, device - ${deviceString}`,
`Error Registering Device in Registry: BotId - ${botId}, device - ${deviceString}. Error ${JSON.stringify(e)}`,
);
return {
userId: null,
status: FAStatus.ERROR,
error: e.message,
};
throw new ServiceUnavailableException();
});
}
}
Expand Down

0 comments on commit d30a956

Please sign in to comment.