Skip to content

Commit

Permalink
Fix error when response is missing included
Browse files Browse the repository at this point in the history
This fixes the following error when the response from the server does
not have the `included` key:

TypeError: Cannot read properties of undefined (reading 'included')

When missing, the value already defaults to an empty array so this
should be safe when it's "undefined" as well.
  • Loading branch information
pelargir committed Jun 10, 2024
1 parent f62c4f3 commit 90de5b7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/alchemy-json_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var structuredClone__default = /*#__PURE__*/_interopDefaultLegacy(structuredClon
function deserialize(originalResponse) {
var response = structuredClone__default["default"](originalResponse);

var included = response.included || [];
var included = response?.included || [];

if (Array.isArray(response.data)) {
return response.data.map(function (data) {
Expand Down
2 changes: 1 addition & 1 deletion src/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function deserialize(originalResponse, options = {}) {
options = {}
}

const included = response.included || []
const included = response?.included || []

if (Array.isArray(response.data)) {
return response.data.map((data) => {
Expand Down

0 comments on commit 90de5b7

Please sign in to comment.