mirror of
				https://github.com/excalidraw/excalidraw.git
				synced 2025-11-04 12:54:23 +01:00 
			
		
		
		
	Proper error handling for creating a link without internet (#577)
* Proper error handling for creating a link without internet * shuffle code a bit Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							1d9cdf4d46
						
					
				
				
					commit
					4b0f788945
				
			@@ -144,25 +144,31 @@ export async function exportToBackend(
 | 
			
		||||
  elements: readonly ExcalidrawElement[],
 | 
			
		||||
  appState: AppState,
 | 
			
		||||
) {
 | 
			
		||||
  const response = await fetch(BACKEND_POST, {
 | 
			
		||||
    method: "POST",
 | 
			
		||||
    headers: { "Content-Type": "application/json" },
 | 
			
		||||
    body: serializeAsJSON(elements, appState),
 | 
			
		||||
  });
 | 
			
		||||
  const json = await response.json();
 | 
			
		||||
  if (json.id) {
 | 
			
		||||
    const url = new URL(window.location.href);
 | 
			
		||||
    url.searchParams.append("id", json.id);
 | 
			
		||||
  let response;
 | 
			
		||||
  try {
 | 
			
		||||
    response = await fetch(BACKEND_POST, {
 | 
			
		||||
      method: "POST",
 | 
			
		||||
      headers: { "Content-Type": "application/json" },
 | 
			
		||||
      body: serializeAsJSON(elements, appState),
 | 
			
		||||
    });
 | 
			
		||||
    const json = await response.json();
 | 
			
		||||
    if (json.id) {
 | 
			
		||||
      const url = new URL(window.location.href);
 | 
			
		||||
      url.searchParams.append("id", json.id);
 | 
			
		||||
 | 
			
		||||
    await navigator.clipboard.writeText(url.toString());
 | 
			
		||||
    window.alert(
 | 
			
		||||
      i18n.t("alerts.copiedToClipboard", {
 | 
			
		||||
        url: url.toString(),
 | 
			
		||||
        interpolation: { escapeValue: false },
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
  } else {
 | 
			
		||||
      await navigator.clipboard.writeText(url.toString());
 | 
			
		||||
      window.alert(
 | 
			
		||||
        i18n.t("alerts.copiedToClipboard", {
 | 
			
		||||
          url: url.toString(),
 | 
			
		||||
          interpolation: { escapeValue: false },
 | 
			
		||||
        }),
 | 
			
		||||
      );
 | 
			
		||||
    } else {
 | 
			
		||||
      window.alert(i18n.t("alerts.couldNotCreateShareableLink"));
 | 
			
		||||
    }
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    window.alert(i18n.t("alerts.couldNotCreateShareableLink"));
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user