diff --git a/packages/medusa-plugin-wishlist/src/api/index.js b/packages/medusa-plugin-wishlist/src/api/index.js index 28da269189..2feb5ea241 100644 --- a/packages/medusa-plugin-wishlist/src/api/index.js +++ b/packages/medusa-plugin-wishlist/src/api/index.js @@ -28,25 +28,21 @@ export default (rootDirectory) => { decode = jwt.decode(token, JWT_SECRET) if (!decode || !decode.customer_id) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - "Invalid token", - 400 - ) + throw new MedusaError(MedusaError.Types.NOT_FOUND, "Invalid token") } } catch (err) { - res.status(400).json(err) + res.status(400).json({ message: err.message }) } try { const customer = await customerService.retrieve(decode.customer_id) - const response = { - wishlist: customer.metadata.wishlist, + const wishlist = { + items: customer.metadata.wishlist, first_name: customer.first_name, } - res.status(200).json({ response }) + res.status(200).json({ wishlist }) } catch (err) { - res.status(400).json(err) + res.status(400).json({ message: err.message }) } } ) diff --git a/packages/medusa-plugin-wishlist/src/api/store/customers.js b/packages/medusa-plugin-wishlist/src/api/store/customers.js index 2d33539ad9..f9de96f32a 100644 --- a/packages/medusa-plugin-wishlist/src/api/store/customers.js +++ b/packages/medusa-plugin-wishlist/src/api/store/customers.js @@ -83,17 +83,15 @@ export default () => { let customer = await customerService.retrieve(req.params.id) - // check customer exists else throw 404 - if (!customer?.id) { - throw new MedusaError(Medusa.Types.NOT_FOUND, "not found", 404) - } - // check customer has wishlist else throw 400 bad request if (!customer?.metadata?.wishlist) { - throw new MedusaError(Medusa.Types.INVALID_DATA, "invalid data", 400) + throw new MedusaError( + Medusa.Types.INVALID_DATA, + "Invalid data - Customer doesn't have a wishlist" + ) } - const token = await jwt.sign( + const token = jwt.sign( { customer_id: customer.id, },