Skip to content

Commit

Permalink
feat: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bigaru committed Aug 8, 2024
1 parent c5c297b commit 0e886f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ApiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { handleBody } from './utils'

const MEDIA_ROUTE = 'wp/v2/media/'

export const callMediaFile = async (url: string, responseContentType: string): Promise<[string?, any?]> => {
export const callMediaFile = async (url: string | undefined, responseContentType: string): Promise<[string?, any?]> => {
if (!url) {
return ['URL is empty', undefined]
}

try {
const response = await fetch(url)

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/zenodo/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const storeCreator = (initalState: Attributes) => {
state.mime = contentType
})

const url = record.files.find((f) => f.key === key)?.links.self ?? ''
const url = record.files.find((f) => f.key === key)?.links.self
const [err, data] = await callMediaFile(url, contentType)

set((state) => {
Expand Down

0 comments on commit 0e886f9

Please sign in to comment.