Display correct placeholder if blob endpoint returns 413 status code

Also makes sure we don't highlight files that are too big
This commit is contained in:
Sebastian Martinez
2024-05-14 16:52:53 +02:00
parent 83041c3e52
commit 8c06938775
3 changed files with 24 additions and 4 deletions
+5 -1
View File
@@ -12,6 +12,7 @@
<style>
.placeholder {
align-items: center;
text-align: center;
color: var(--color-foreground-dim);
display: flex;
flex-direction: column;
@@ -26,5 +27,8 @@
<div class="placeholder" class:inline>
<Icon name={iconName} size={iconSize} />
{caption}
{#each caption.split("\n") as line}
{line}
<br />
{/each}
</div>
+7
View File
@@ -195,6 +195,13 @@
blob={blobResult.blob}
highlighted={blobResult.highlighted}
rawPath={rawPath(tree.lastCommit.id)} />
{:else if blobResult.error.status === 413}
<div class="placeholder">
<Placeholder
iconName="exclamation-circle"
caption="This file is too big to be displayed.
If you want to explore this file clone this repository locally." />
</div>
{:else if path === "/"}
<div class="placeholder">
<Placeholder iconName="no-file" caption="No README found." />
+12 -3
View File
@@ -198,7 +198,7 @@ export type ProjectLoadedRoute =
export type BlobResult =
| { ok: true; blob: Blob; highlighted: Syntax.Root | undefined }
| { ok: false; error: { message: string; path: string } };
| { ok: false; error: { status?: number; message: string; path: string } };
export type PatchView =
| {
@@ -477,8 +477,17 @@ async function loadBlob(
? await Syntax.highlight(blob.content, blob.path.split(".").pop() ?? "")
: undefined,
};
} catch {
if (path === "/") {
} catch (e: unknown) {
if (e instanceof ResponseError) {
return {
ok: false,
error: {
status: e.status,
message: "Not able to load file",
path,
},
};
} else if (path === "/") {
return {
ok: false,
error: {