feat(utils): add error message when manager is not found in context (#11693)

This commit is contained in:
Riqwan Thamir
2025-03-03 15:50:34 +01:00
committed by GitHub
parent c28ae573e5
commit ab96ad3b82
2 changed files with 15 additions and 0 deletions
@@ -1,4 +1,5 @@
import { Context } from "@medusajs/types"
import { isPresent } from "../../common"
import { MedusaContextType } from "./context-parameter"
export function InjectManager(managerProperty?: string): MethodDecorator {
@@ -40,6 +41,15 @@ export function InjectManager(managerProperty?: string): MethodDecorator {
? this
: this[managerProperty]
if (
!isPresent(resourceWithManager) &&
!isPresent(originalContext.manager)
) {
throw new Error(
`Could not find a manager in the context. Ensure that ${this.managerProperty} is set on your service that points to a repository.`
)
}
copiedContext.manager =
originalContext.manager ?? resourceWithManager.getFreshManager()