feat(medusa): add if statement to idempotency-key initialize (#3555)

* add if statement to idempotency-key initialize

* add changeset
This commit is contained in:
Philip Korsholm
2023-03-22 21:34:50 +01:00
committed by GitHub
parent 74bc4b16a0
commit 3171b0e518
2 changed files with 18 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): if no headerkey is provided when initilizing idempotency key, no attempt is made at fetching the key

View File

@@ -1,16 +1,17 @@
import { isDefined, MedusaError } from "medusa-core-utils"
import { v4 } from "uuid"
import { TransactionBaseService } from "../interfaces"
import { DeepPartial, EntityManager } from "typeorm"
import { IdempotencyKeyRepository } from "../repositories/idempotency-key"
import { IdempotencyKey } from "../models"
import {
CreateIdempotencyKeyInput,
IdempotencyCallbackResult,
} from "../types/idempotency-key"
import { Selector } from "../types/common"
import { DeepPartial, EntityManager } from "typeorm"
import { MedusaError, isDefined } from "medusa-core-utils"
import { buildQuery, isString } from "../utils"
import { IdempotencyKey } from "../models"
import { IdempotencyKeyRepository } from "../repositories/idempotency-key"
import { Selector } from "../types/common"
import { TransactionBaseService } from "../interfaces"
import { v4 } from "uuid"
const KEY_LOCKED_TIMEOUT = 1000
type InjectedDependencies = {
@@ -43,9 +44,11 @@ class IdempotencyKeyService extends TransactionBaseService {
reqPath: string
): Promise<IdempotencyKey> {
return await this.atomicPhase_(async () => {
const key = await this.retrieve(headerKey).catch(() => void 0)
if (key) {
return key
if (headerKey) {
const key = await this.retrieve(headerKey).catch(() => void 0)
if (key) {
return key
}
}
return await this.create({
request_method: reqMethod,