chore(): Update module provider retrieval error message and type (#10138)
Partially RESOLVES FRMW-2802 **What** Improve error message and change the error type when retrieving a provider from a local container fail
This commit is contained in:
1 parent
661ea7865c
commit
7aa990795c
12 files changed
+94
-24
No files matched your search
@@ -84,7 +84,8 @@ moduleIntegrationTestRunner({
|
||||
|
||||
expect(err).toEqual({
|
||||
success: false,
|
||||
error: "Could not find a auth provider with id: facebook",
|
||||
error:
|
||||
"\n Unable to retrieve the auth provider with id: facebook\n Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.\n ",
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
Context,
|
||||
DAL,
|
||||
InternalModuleDeclaration,
|
||||
Logger,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/framework/types"
|
||||
@@ -24,6 +25,7 @@ type InjectedDependencies = {
|
||||
authIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
providerIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
authProviderService: AuthProviderService
|
||||
logger?: Logger
|
||||
}
|
||||
export default class AuthModuleService
|
||||
extends MedusaService<{
|
||||
|
||||
@@ -3,21 +3,26 @@ import {
|
||||
AuthenticationResponse,
|
||||
AuthIdentityProviderService,
|
||||
AuthTypes,
|
||||
Logger,
|
||||
} from "@medusajs/framework/types"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
import { AuthProviderRegistrationPrefix } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
[
|
||||
key: `${typeof AuthProviderRegistrationPrefix}${string}`
|
||||
]: AuthTypes.IAuthProvider
|
||||
logger?: Logger
|
||||
}
|
||||
|
||||
export default class AuthProviderService {
|
||||
protected dependencies: InjectedDependencies
|
||||
#logger: Logger
|
||||
|
||||
constructor(container: InjectedDependencies) {
|
||||
this.dependencies = container
|
||||
this.#logger = container["logger"]
|
||||
? container.logger
|
||||
: (console as unknown as Logger)
|
||||
}
|
||||
|
||||
protected retrieveProviderRegistration(
|
||||
@@ -26,10 +31,12 @@ export default class AuthProviderService {
|
||||
try {
|
||||
return this.dependencies[`${AuthProviderRegistrationPrefix}${providerId}`]
|
||||
} catch (err) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`Could not find a auth provider with id: ${providerId}`
|
||||
)
|
||||
const errMessage = `
|
||||
Unable to retrieve the auth provider with id: ${providerId}
|
||||
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
|
||||
`
|
||||
this.#logger.error(errMessage)
|
||||
throw new Error(errMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user