enzostvs HF Staff commited on
Commit
26c5e3c
·
1 Parent(s): b179f9d

try to fix error

Browse files
Files changed (1) hide show
  1. app/api/ask/route.ts +29 -14
app/api/ask/route.ts CHANGED
@@ -638,11 +638,18 @@ export async function PUT(request: NextRequest) {
638
  type: "space",
639
  name: `${user.name}/${formattedTitle}`,
640
  };
641
- const { repoUrl} = await createRepo({
642
- repo,
643
- accessToken: user.token as string,
644
- });
645
- repoId = repoUrl.split("/").slice(-2).join("/");
 
 
 
 
 
 
 
646
  const colorFrom = COLORS[Math.floor(Math.random() * COLORS.length)];
647
  const colorTo = COLORS[Math.floor(Math.random() * COLORS.length)];
648
  const README = `---
@@ -662,15 +669,23 @@ This project was created with [DeepSite](https://huggingface.co/deepsite).
662
  files.push(new File([README], "README.md", { type: "text/markdown" }));
663
  }
664
 
665
- const response = await uploadFiles({
666
- repo: {
667
- type: "space",
668
- name: repoId,
669
- },
670
- files,
671
- commitTitle: prompt,
672
- accessToken: user.token as string,
673
- });
 
 
 
 
 
 
 
 
674
 
675
  return NextResponse.json({
676
  ok: true,
 
638
  type: "space",
639
  name: `${user.name}/${formattedTitle}`,
640
  };
641
+
642
+ try {
643
+ const { repoUrl} = await createRepo({
644
+ repo,
645
+ accessToken: user.token as string,
646
+ });
647
+ repoId = repoUrl.split("/").slice(-2).join("/");
648
+ } catch (createRepoError: any) {
649
+ console.error("++CREATE REPO ERROR++", createRepoError);
650
+ throw new Error(`Failed to create repository: ${createRepoError.message || 'Unknown error'}`);
651
+ }
652
+
653
  const colorFrom = COLORS[Math.floor(Math.random() * COLORS.length)];
654
  const colorTo = COLORS[Math.floor(Math.random() * COLORS.length)];
655
  const README = `---
 
669
  files.push(new File([README], "README.md", { type: "text/markdown" }));
670
  }
671
 
672
+ let response;
673
+ try {
674
+ response = await uploadFiles({
675
+ repo: {
676
+ type: "space",
677
+ name: repoId,
678
+ },
679
+ files,
680
+ commitTitle: prompt,
681
+ accessToken: user.token as string,
682
+ });
683
+ } catch (uploadError: any) {
684
+ console.error("++UPLOAD FILES ERROR++", uploadError);
685
+ console.error("++UPLOAD FILES ERROR MESSAGE++", uploadError.message);
686
+ console.error("++REPO ID++", repoId);
687
+ throw new Error(`Failed to upload files to repository: ${uploadError.message || 'Unknown error'}`);
688
+ }
689
 
690
  return NextResponse.json({
691
  ok: true,