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:
Adrien de Peretti
2024-11-19 12:19:19 +01:00
committed by GitHub
parent 661ea7865c
commit 7aa990795c
12 changed files with 94 additions and 24 deletions

View File

@@ -0,0 +1,9 @@
---
"@medusajs/auth": patch
"@medusajs/fulfillment": patch
"@medusajs/locking": patch
"@medusajs/notification": patch
"@medusajs/payment": patch
---
chore(): Update module provider retrieval error message and type

View File

@@ -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 ",
})
})

View File

@@ -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<{

View File

@@ -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)
}
}

View File

@@ -7,6 +7,7 @@ import {
FulfillmentTypes,
IFulfillmentModuleService,
InternalModuleDeclaration,
Logger,
ModuleJoinerConfig,
ModulesSdkTypes,
ShippingOptionDTO,
@@ -76,6 +77,7 @@ type InjectedDependencies = {
shippingOptionTypeService: ModulesSdkTypes.IMedusaInternalService<any>
fulfillmentProviderService: FulfillmentProviderService
fulfillmentService: ModulesSdkTypes.IMedusaInternalService<any>
logger?: Logger
}
export default class FulfillmentModuleService

View File

@@ -3,6 +3,7 @@ import {
DAL,
FulfillmentTypes,
IFulfillmentProvider,
Logger,
} from "@medusajs/framework/types"
import {
MedusaError,
@@ -12,6 +13,7 @@ import {
import { FulfillmentProvider } from "@models"
type InjectedDependencies = {
logger?: Logger
fulfillmentProviderRepository: DAL.RepositoryService
[key: `fp_${string}`]: FulfillmentTypes.IFulfillmentProvider
}
@@ -22,11 +24,15 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
FulfillmentProvider
) {
protected readonly fulfillmentProviderRepository_: DAL.RepositoryService
#logger: Logger
constructor(container: InjectedDependencies) {
super(container)
this.fulfillmentProviderRepository_ =
container.fulfillmentProviderRepository
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}
static getRegistrationIdentifier(
@@ -48,10 +54,12 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
try {
return this.__container__[`fp_${providerId}`]
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a fulfillment provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the fulfillment 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)
}
}

View File

@@ -2,6 +2,7 @@ import {
Context,
ILockingModule,
InternalModuleDeclaration,
Logger,
} from "@medusajs/types"
import { EntityManager } from "@mikro-orm/core"
import { LockingDefaultProvider } from "@types"
@@ -10,6 +11,7 @@ import LockingProviderService from "./locking-provider"
type InjectedDependencies = {
manager: EntityManager
lockingProviderService: LockingProviderService
logger?: Logger
[LockingDefaultProvider]: string
}

View File

@@ -1,16 +1,25 @@
import { Constructor, ILockingProvider } from "@medusajs/framework/types"
import {
Constructor,
ILockingProvider,
Logger,
} from "@medusajs/framework/types"
import { MedusaError } from "@medusajs/framework/utils"
import { LockingProviderRegistrationPrefix } from "../types"
type InjectedDependencies = {
[key: `lp_${string}`]: ILockingProvider
logger?: Logger
}
export default class LockingProviderService {
protected __container__: InjectedDependencies
#logger: Logger
constructor(container: InjectedDependencies) {
this.__container__ = container
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}
static getRegistrationIdentifier(
@@ -31,10 +40,12 @@ export default class LockingProviderService {
`${LockingProviderRegistrationPrefix}${providerId}`
]
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a locking provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the locking 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)
}
}
}

View File

@@ -4,6 +4,7 @@ import {
InferEntityType,
INotificationModuleService,
InternalModuleDeclaration,
Logger,
ModulesSdkTypes,
NotificationTypes,
} from "@medusajs/framework/types"
@@ -22,6 +23,7 @@ import { eventBuilders } from "@utils"
import NotificationProviderService from "./notification-provider"
type InjectedDependencies = {
logger?: Logger
baseRepository: DAL.RepositoryService
notificationService: ModulesSdkTypes.IMedusaInternalService<
typeof Notification

View File

@@ -1,13 +1,15 @@
import {
DAL,
InferEntityType,
Logger,
NotificationTypes,
} from "@medusajs/framework/types"
import { MedusaError, ModulesSdkUtils } from "@medusajs/framework/utils"
import { ModulesSdkUtils } from "@medusajs/framework/utils"
import { NotificationProvider } from "@models"
import { NotificationProviderRegistrationPrefix } from "@types"
type InjectedDependencies = {
logger?: Logger
notificationProviderRepository: DAL.RepositoryService<
InferEntityType<typeof NotificationProvider>
>
@@ -25,7 +27,11 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
protected readonly notificationProviderRepository_: DAL.RepositoryService<
InferEntityType<typeof NotificationProvider>
>
// We can store the providers in a memory since they can only be registered on startup and not changed during runtime
#logger: Logger
protected providersCache: Map<
string,
InferEntityType<typeof NotificationProvider>
@@ -35,6 +41,9 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
super(container)
this.notificationProviderRepository_ =
container.notificationProviderRepository
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}
protected retrieveProviderRegistration(
@@ -45,10 +54,12 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
`${NotificationProviderRegistrationPrefix}${providerId}`
]
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a notification provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the notification 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)
}
}

View File

@@ -13,6 +13,7 @@ import {
FindConfig,
InternalModuleDeclaration,
IPaymentModuleService,
Logger,
ModuleJoinerConfig,
ModulesSdkTypes,
PaymentCollectionDTO,
@@ -54,6 +55,7 @@ import { joinerConfig } from "../joiner-config"
import PaymentProviderService from "./payment-provider"
type InjectedDependencies = {
logger?: Logger
baseRepository: DAL.RepositoryService
paymentService: ModulesSdkTypes.IMedusaInternalService<any>
captureService: ModulesSdkTypes.IMedusaInternalService<any>

View File

@@ -3,6 +3,7 @@ import {
CreatePaymentProviderSession,
DAL,
IPaymentProvider,
Logger,
PaymentProviderAuthorizeResponse,
PaymentProviderDataInput,
PaymentProviderError,
@@ -21,6 +22,7 @@ import { PaymentProvider } from "@models"
import { EOL } from "os"
type InjectedDependencies = {
logger?: Logger
paymentProviderRepository: DAL.RepositoryService
[key: `pp_${string}`]: IPaymentProvider
}
@@ -28,14 +30,25 @@ type InjectedDependencies = {
export default class PaymentProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
PaymentProvider
) {
#logger: Logger
constructor(container: InjectedDependencies) {
super(container)
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}
retrieveProvider(providerId: string): IPaymentProvider {
try {
return this.__container__[providerId] as IPaymentProvider
} catch (e) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a payment provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the payment 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)
}
}