Skip to content

Commit

Permalink
fix(store): Error message for type error in storage set method
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Apr 19, 2024
1 parent ca64c65 commit dbff629
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,18 +1221,33 @@ function set(model, values = {}) {
(result === undefined || typeof result !== "object")
) {
throw TypeError(
`Storage 'set' method must return a Promise, an instance, or null: ${result}`,
stringifyModel(
config.model,
`Storage 'set' method must return a Promise, an instance, or null: ${result}`,
),
);
}

result = Promise.resolve(result)
.then((data) => {
if (data === undefined || typeof data !== "object") {
throw TypeError(
stringifyModel(
config.model,
`Storage 'set' method must resolve to an instance, or null: ${data}`,
),
);
}

const resultModel =
data === localModel ? localModel : config.create(data);

if (isInstance && resultModel && id !== resultModel.id) {
throw TypeError(
`Local and storage data must have the same id: '${id}', '${resultModel.id}'`,
stringifyModel(
config.model,
`Local and storage data must have the same id: '${id}', '${resultModel.id}'`,
),
);
}

Expand Down

0 comments on commit dbff629

Please sign in to comment.