feat(utils): add error message when manager is not found in context (#11693)
This commit is contained in:
1 parent
c28ae573e5
commit
ab96ad3b82
2 files changed
+15
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(utils): add error message when manager is not found
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Context } from "@medusajs/types"
|
import { Context } from "@medusajs/types"
|
||||||
|
import { isPresent } from "../../common"
|
||||||
import { MedusaContextType } from "./context-parameter"
|
import { MedusaContextType } from "./context-parameter"
|
||||||
|
|
||||||
export function InjectManager(managerProperty?: string): MethodDecorator {
|
export function InjectManager(managerProperty?: string): MethodDecorator {
|
||||||
@@ -40,6 +41,15 @@ export function InjectManager(managerProperty?: string): MethodDecorator {
|
|||||||
? this
|
? this
|
||||||
: this[managerProperty]
|
: 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 =
|
copiedContext.manager =
|
||||||
originalContext.manager ?? resourceWithManager.getFreshManager()
|
originalContext.manager ?? resourceWithManager.getFreshManager()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user