Skip to content

Media results not checked forundefined before decoding #2833

Closed

Description

Description

Sometimes a request for related media returns undefined in the results. This causes an error when we try to map decodeMediaData over the results array:

results: res.data.results.map((item) =>
decodeMediaData(item, this.mediaType)
) as DetailFromMediaType<T>[],

A simple solution could be to add ?? [] to the results. This will replace the undefined value in results with an empty array, which can be used in the map here:

results: (res.data.results ?? []).map((item) =>

Sentry issue

OPENVERSE-FRONTEND-1AG

TypeError: Cannot read properties of undefined (reading 'map')
  at key (./src/data/media-service.ts:102:33)
  at Generator.next (<anonymous>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

  • Status

    ✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions