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:
committed by
GitHub
parent
661ea7865c
commit
7aa990795c
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user