async function loadItemMeta()

in app/ItemView/LoadItem.ts [11:44]


async function loadItemMeta(
  vidispineBaseUrl: string,
  itemId: string
): Promise<VidispineItem> {
  const targetUrl = `${vidispineBaseUrl}/API/item/${itemId}?content=metadata,shape,uri&methodType=AUTO`;
  console.debug("loading item data from ", targetUrl);
  try {
    const result = await axios.get(targetUrl, {
      headers: { Accept: "application/json" },
    });
    return new VidispineItem(result.data);
  } catch (err) {
    console.error("Could not load from ", targetUrl, ": ", err);

    if (err.response) {
      switch (err.response.status) {
        case 404:
          throw "The item does not exist.";
        case 400:
          throw "The item ID is not valid";
        case 503 | 502:
          throw "The server is not responding, retrying...";
        case 500:
          throw "There is a server problem, please report this to multimediatech@theguardian.com";
        default:
          console.error(err);
          throw "Unable to load the given item. Please refer to the console for more information.";
      }
    } else {
      console.error(err);
      throw "Unable to load the given item. Please refer to the console for more information.";
    }
  }
}