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
@@ -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
|
||||||
@@ -84,7 +84,8 @@ moduleIntegrationTestRunner({
|
|||||||
|
|
||||||
expect(err).toEqual({
|
expect(err).toEqual({
|
||||||
success: false,
|
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,
|
Context,
|
||||||
DAL,
|
DAL,
|
||||||
InternalModuleDeclaration,
|
InternalModuleDeclaration,
|
||||||
|
Logger,
|
||||||
ModuleJoinerConfig,
|
ModuleJoinerConfig,
|
||||||
ModulesSdkTypes,
|
ModulesSdkTypes,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
@@ -24,6 +25,7 @@ type InjectedDependencies = {
|
|||||||
authIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
authIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
providerIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
providerIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
authProviderService: AuthProviderService
|
authProviderService: AuthProviderService
|
||||||
|
logger?: Logger
|
||||||
}
|
}
|
||||||
export default class AuthModuleService
|
export default class AuthModuleService
|
||||||
extends MedusaService<{
|
extends MedusaService<{
|
||||||
|
|||||||
@@ -3,21 +3,26 @@ import {
|
|||||||
AuthenticationResponse,
|
AuthenticationResponse,
|
||||||
AuthIdentityProviderService,
|
AuthIdentityProviderService,
|
||||||
AuthTypes,
|
AuthTypes,
|
||||||
|
Logger,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import { MedusaError } from "@medusajs/framework/utils"
|
|
||||||
import { AuthProviderRegistrationPrefix } from "@types"
|
import { AuthProviderRegistrationPrefix } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
[
|
[
|
||||||
key: `${typeof AuthProviderRegistrationPrefix}${string}`
|
key: `${typeof AuthProviderRegistrationPrefix}${string}`
|
||||||
]: AuthTypes.IAuthProvider
|
]: AuthTypes.IAuthProvider
|
||||||
|
logger?: Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AuthProviderService {
|
export default class AuthProviderService {
|
||||||
protected dependencies: InjectedDependencies
|
protected dependencies: InjectedDependencies
|
||||||
|
#logger: Logger
|
||||||
|
|
||||||
constructor(container: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
this.dependencies = container
|
this.dependencies = container
|
||||||
|
this.#logger = container["logger"]
|
||||||
|
? container.logger
|
||||||
|
: (console as unknown as Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected retrieveProviderRegistration(
|
protected retrieveProviderRegistration(
|
||||||
@@ -26,10 +31,12 @@ export default class AuthProviderService {
|
|||||||
try {
|
try {
|
||||||
return this.dependencies[`${AuthProviderRegistrationPrefix}${providerId}`]
|
return this.dependencies[`${AuthProviderRegistrationPrefix}${providerId}`]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new MedusaError(
|
const errMessage = `
|
||||||
MedusaError.Types.NOT_FOUND,
|
Unable to retrieve the auth provider with id: ${providerId}
|
||||||
`Could not find a 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
FulfillmentTypes,
|
FulfillmentTypes,
|
||||||
IFulfillmentModuleService,
|
IFulfillmentModuleService,
|
||||||
InternalModuleDeclaration,
|
InternalModuleDeclaration,
|
||||||
|
Logger,
|
||||||
ModuleJoinerConfig,
|
ModuleJoinerConfig,
|
||||||
ModulesSdkTypes,
|
ModulesSdkTypes,
|
||||||
ShippingOptionDTO,
|
ShippingOptionDTO,
|
||||||
@@ -76,6 +77,7 @@ type InjectedDependencies = {
|
|||||||
shippingOptionTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
shippingOptionTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
fulfillmentProviderService: FulfillmentProviderService
|
fulfillmentProviderService: FulfillmentProviderService
|
||||||
fulfillmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
fulfillmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
|
logger?: Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class FulfillmentModuleService
|
export default class FulfillmentModuleService
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
DAL,
|
DAL,
|
||||||
FulfillmentTypes,
|
FulfillmentTypes,
|
||||||
IFulfillmentProvider,
|
IFulfillmentProvider,
|
||||||
|
Logger,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
MedusaError,
|
MedusaError,
|
||||||
@@ -12,6 +13,7 @@ import {
|
|||||||
import { FulfillmentProvider } from "@models"
|
import { FulfillmentProvider } from "@models"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
|
logger?: Logger
|
||||||
fulfillmentProviderRepository: DAL.RepositoryService
|
fulfillmentProviderRepository: DAL.RepositoryService
|
||||||
[key: `fp_${string}`]: FulfillmentTypes.IFulfillmentProvider
|
[key: `fp_${string}`]: FulfillmentTypes.IFulfillmentProvider
|
||||||
}
|
}
|
||||||
@@ -22,11 +24,15 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
|
|||||||
FulfillmentProvider
|
FulfillmentProvider
|
||||||
) {
|
) {
|
||||||
protected readonly fulfillmentProviderRepository_: DAL.RepositoryService
|
protected readonly fulfillmentProviderRepository_: DAL.RepositoryService
|
||||||
|
#logger: Logger
|
||||||
|
|
||||||
constructor(container: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
super(container)
|
super(container)
|
||||||
this.fulfillmentProviderRepository_ =
|
this.fulfillmentProviderRepository_ =
|
||||||
container.fulfillmentProviderRepository
|
container.fulfillmentProviderRepository
|
||||||
|
this.#logger = container["logger"]
|
||||||
|
? container.logger
|
||||||
|
: (console as unknown as Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
static getRegistrationIdentifier(
|
static getRegistrationIdentifier(
|
||||||
@@ -48,10 +54,12 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
|
|||||||
try {
|
try {
|
||||||
return this.__container__[`fp_${providerId}`]
|
return this.__container__[`fp_${providerId}`]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new MedusaError(
|
const errMessage = `
|
||||||
MedusaError.Types.NOT_FOUND,
|
Unable to retrieve the fulfillment provider with id: ${providerId}
|
||||||
`Could not find a 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
Context,
|
Context,
|
||||||
ILockingModule,
|
ILockingModule,
|
||||||
InternalModuleDeclaration,
|
InternalModuleDeclaration,
|
||||||
|
Logger,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { EntityManager } from "@mikro-orm/core"
|
import { EntityManager } from "@mikro-orm/core"
|
||||||
import { LockingDefaultProvider } from "@types"
|
import { LockingDefaultProvider } from "@types"
|
||||||
@@ -10,6 +11,7 @@ import LockingProviderService from "./locking-provider"
|
|||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
lockingProviderService: LockingProviderService
|
lockingProviderService: LockingProviderService
|
||||||
|
logger?: Logger
|
||||||
[LockingDefaultProvider]: string
|
[LockingDefaultProvider]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 { MedusaError } from "@medusajs/framework/utils"
|
||||||
import { LockingProviderRegistrationPrefix } from "../types"
|
import { LockingProviderRegistrationPrefix } from "../types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
[key: `lp_${string}`]: ILockingProvider
|
[key: `lp_${string}`]: ILockingProvider
|
||||||
|
logger?: Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LockingProviderService {
|
export default class LockingProviderService {
|
||||||
protected __container__: InjectedDependencies
|
protected __container__: InjectedDependencies
|
||||||
|
#logger: Logger
|
||||||
|
|
||||||
constructor(container: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
this.__container__ = container
|
this.__container__ = container
|
||||||
|
this.#logger = container["logger"]
|
||||||
|
? container.logger
|
||||||
|
: (console as unknown as Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
static getRegistrationIdentifier(
|
static getRegistrationIdentifier(
|
||||||
@@ -31,10 +40,12 @@ export default class LockingProviderService {
|
|||||||
`${LockingProviderRegistrationPrefix}${providerId}`
|
`${LockingProviderRegistrationPrefix}${providerId}`
|
||||||
]
|
]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new MedusaError(
|
const errMessage = `
|
||||||
MedusaError.Types.NOT_FOUND,
|
Unable to retrieve the locking provider with id: ${providerId}
|
||||||
`Could not find a 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
InferEntityType,
|
InferEntityType,
|
||||||
INotificationModuleService,
|
INotificationModuleService,
|
||||||
InternalModuleDeclaration,
|
InternalModuleDeclaration,
|
||||||
|
Logger,
|
||||||
ModulesSdkTypes,
|
ModulesSdkTypes,
|
||||||
NotificationTypes,
|
NotificationTypes,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
@@ -22,6 +23,7 @@ import { eventBuilders } from "@utils"
|
|||||||
import NotificationProviderService from "./notification-provider"
|
import NotificationProviderService from "./notification-provider"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
|
logger?: Logger
|
||||||
baseRepository: DAL.RepositoryService
|
baseRepository: DAL.RepositoryService
|
||||||
notificationService: ModulesSdkTypes.IMedusaInternalService<
|
notificationService: ModulesSdkTypes.IMedusaInternalService<
|
||||||
typeof Notification
|
typeof Notification
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import {
|
import {
|
||||||
DAL,
|
DAL,
|
||||||
InferEntityType,
|
InferEntityType,
|
||||||
|
Logger,
|
||||||
NotificationTypes,
|
NotificationTypes,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import { MedusaError, ModulesSdkUtils } from "@medusajs/framework/utils"
|
import { ModulesSdkUtils } from "@medusajs/framework/utils"
|
||||||
import { NotificationProvider } from "@models"
|
import { NotificationProvider } from "@models"
|
||||||
import { NotificationProviderRegistrationPrefix } from "@types"
|
import { NotificationProviderRegistrationPrefix } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
|
logger?: Logger
|
||||||
notificationProviderRepository: DAL.RepositoryService<
|
notificationProviderRepository: DAL.RepositoryService<
|
||||||
InferEntityType<typeof NotificationProvider>
|
InferEntityType<typeof NotificationProvider>
|
||||||
>
|
>
|
||||||
@@ -25,7 +27,11 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
|
|||||||
protected readonly notificationProviderRepository_: DAL.RepositoryService<
|
protected readonly notificationProviderRepository_: DAL.RepositoryService<
|
||||||
InferEntityType<typeof NotificationProvider>
|
InferEntityType<typeof NotificationProvider>
|
||||||
>
|
>
|
||||||
|
|
||||||
// We can store the providers in a memory since they can only be registered on startup and not changed during runtime
|
// 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<
|
protected providersCache: Map<
|
||||||
string,
|
string,
|
||||||
InferEntityType<typeof NotificationProvider>
|
InferEntityType<typeof NotificationProvider>
|
||||||
@@ -35,6 +41,9 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
|
|||||||
super(container)
|
super(container)
|
||||||
this.notificationProviderRepository_ =
|
this.notificationProviderRepository_ =
|
||||||
container.notificationProviderRepository
|
container.notificationProviderRepository
|
||||||
|
this.#logger = container["logger"]
|
||||||
|
? container.logger
|
||||||
|
: (console as unknown as Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected retrieveProviderRegistration(
|
protected retrieveProviderRegistration(
|
||||||
@@ -45,10 +54,12 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
|
|||||||
`${NotificationProviderRegistrationPrefix}${providerId}`
|
`${NotificationProviderRegistrationPrefix}${providerId}`
|
||||||
]
|
]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new MedusaError(
|
const errMessage = `
|
||||||
MedusaError.Types.NOT_FOUND,
|
Unable to retrieve the notification provider with id: ${providerId}
|
||||||
`Could not find a 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
FindConfig,
|
FindConfig,
|
||||||
InternalModuleDeclaration,
|
InternalModuleDeclaration,
|
||||||
IPaymentModuleService,
|
IPaymentModuleService,
|
||||||
|
Logger,
|
||||||
ModuleJoinerConfig,
|
ModuleJoinerConfig,
|
||||||
ModulesSdkTypes,
|
ModulesSdkTypes,
|
||||||
PaymentCollectionDTO,
|
PaymentCollectionDTO,
|
||||||
@@ -54,6 +55,7 @@ import { joinerConfig } from "../joiner-config"
|
|||||||
import PaymentProviderService from "./payment-provider"
|
import PaymentProviderService from "./payment-provider"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
|
logger?: Logger
|
||||||
baseRepository: DAL.RepositoryService
|
baseRepository: DAL.RepositoryService
|
||||||
paymentService: ModulesSdkTypes.IMedusaInternalService<any>
|
paymentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
captureService: ModulesSdkTypes.IMedusaInternalService<any>
|
captureService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
CreatePaymentProviderSession,
|
CreatePaymentProviderSession,
|
||||||
DAL,
|
DAL,
|
||||||
IPaymentProvider,
|
IPaymentProvider,
|
||||||
|
Logger,
|
||||||
PaymentProviderAuthorizeResponse,
|
PaymentProviderAuthorizeResponse,
|
||||||
PaymentProviderDataInput,
|
PaymentProviderDataInput,
|
||||||
PaymentProviderError,
|
PaymentProviderError,
|
||||||
@@ -21,6 +22,7 @@ import { PaymentProvider } from "@models"
|
|||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
|
logger?: Logger
|
||||||
paymentProviderRepository: DAL.RepositoryService
|
paymentProviderRepository: DAL.RepositoryService
|
||||||
[key: `pp_${string}`]: IPaymentProvider
|
[key: `pp_${string}`]: IPaymentProvider
|
||||||
}
|
}
|
||||||
@@ -28,14 +30,25 @@ type InjectedDependencies = {
|
|||||||
export default class PaymentProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
export default class PaymentProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||||
PaymentProvider
|
PaymentProvider
|
||||||
) {
|
) {
|
||||||
|
#logger: Logger
|
||||||
|
|
||||||
|
constructor(container: InjectedDependencies) {
|
||||||
|
super(container)
|
||||||
|
this.#logger = container["logger"]
|
||||||
|
? container.logger
|
||||||
|
: (console as unknown as Logger)
|
||||||
|
}
|
||||||
|
|
||||||
retrieveProvider(providerId: string): IPaymentProvider {
|
retrieveProvider(providerId: string): IPaymentProvider {
|
||||||
try {
|
try {
|
||||||
return this.__container__[providerId] as IPaymentProvider
|
return this.__container__[providerId] as IPaymentProvider
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new MedusaError(
|
const errMessage = `
|
||||||
MedusaError.Types.NOT_FOUND,
|
Unable to retrieve the payment provider with id: ${providerId}
|
||||||
`Could not find a 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user