mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-18 19:30:27 +08:00
Improve error when http-api outdated
Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
+5
-5
@@ -38,19 +38,19 @@ export async function get(
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
throw new ApiError(urlString, "API request failed");
|
||||
throw new ApiError("API request failed", urlString);
|
||||
}
|
||||
|
||||
if (! response.ok) {
|
||||
throw new ApiError(urlString, "Not found");
|
||||
throw new ApiError("Not found", urlString);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
class ApiError extends Error {
|
||||
url: string;
|
||||
export class ApiError extends Error {
|
||||
url?: string;
|
||||
|
||||
constructor(url: string, message: string) {
|
||||
constructor(message: string, url?: string) {
|
||||
super(message);
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import type { Project } from "@app/project";
|
||||
import Loading from "@app/Loading.svelte";
|
||||
import { groupCommitHistory, GroupedCommitsHistory } from "@app/commit";
|
||||
import Message from "@app/Message.svelte";
|
||||
|
||||
export let project: Project;
|
||||
export let commit: string;
|
||||
@@ -66,8 +67,12 @@
|
||||
</div>
|
||||
{:catch err}
|
||||
<div class="history">
|
||||
<div class="error error-message text-xsmall">
|
||||
<div>API request to <code class="text-xsmall">{err.url}</code> failed.</div>
|
||||
</div>
|
||||
<Message error>
|
||||
{#if err.url}
|
||||
API request to <code class="text-xsmall">{err.url}</code> failed.
|
||||
{:else}
|
||||
{err.message}
|
||||
{/if}
|
||||
</Message>
|
||||
</div>
|
||||
{/await}
|
||||
|
||||
+34
-29
@@ -1,5 +1,6 @@
|
||||
import type { Stats } from "@app/project";
|
||||
import type { Diff } from "@app/diff";
|
||||
import { ApiError } from "@app/api";
|
||||
|
||||
export interface CommitsHistory {
|
||||
headers: CommitMetadata[];
|
||||
@@ -37,7 +38,7 @@ export interface Person {
|
||||
}
|
||||
|
||||
export interface CommitContext {
|
||||
committer: {
|
||||
committer?: {
|
||||
peer: {
|
||||
id: string;
|
||||
person: Person;
|
||||
@@ -92,36 +93,40 @@ export function groupCommits(commits: { header: CommitHeader; context: CommitCon
|
||||
const groupedCommits: CommitGroup[] = [];
|
||||
let groupDate: Date | undefined = undefined;
|
||||
|
||||
commits = commits.sort((a, b) => {
|
||||
if (a.header.committerTime > b.header.committerTime) {
|
||||
return -1;
|
||||
} else if (a.header.committerTime < b.header.committerTime) {
|
||||
return 1;
|
||||
try {
|
||||
commits = commits.sort((a, b) => {
|
||||
if (a.header.committerTime > b.header.committerTime) {
|
||||
return -1;
|
||||
} else if (a.header.committerTime < b.header.committerTime) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
for (const commit of commits) {
|
||||
const time = commit.header.committerTime * 1000;
|
||||
const date = new Date(time);
|
||||
const isNewDay =
|
||||
!groupedCommits.length ||
|
||||
!groupDate ||
|
||||
date.getDate() < groupDate.getDate() ||
|
||||
date.getMonth() < groupDate.getMonth() ||
|
||||
date.getFullYear() < groupDate.getFullYear();
|
||||
|
||||
if (isNewDay) {
|
||||
groupedCommits.push({
|
||||
time: formatGroupTime(time),
|
||||
commits: [],
|
||||
});
|
||||
groupDate = date;
|
||||
}
|
||||
groupedCommits[groupedCommits.length - 1].commits.push(commit);
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
for (const commit of commits) {
|
||||
const time = commit.header.committerTime * 1000;
|
||||
const date = new Date(time);
|
||||
const isNewDay =
|
||||
!groupedCommits.length ||
|
||||
!groupDate ||
|
||||
date.getDate() < groupDate.getDate() ||
|
||||
date.getMonth() < groupDate.getMonth() ||
|
||||
date.getFullYear() < groupDate.getFullYear();
|
||||
|
||||
if (isNewDay) {
|
||||
groupedCommits.push({
|
||||
time: formatGroupTime(time),
|
||||
commits: [],
|
||||
});
|
||||
groupDate = date;
|
||||
}
|
||||
groupedCommits[groupedCommits.length - 1].commits.push(commit);
|
||||
return groupedCommits;
|
||||
} catch (err) {
|
||||
throw new ApiError("Not able to create commit history, please consider updating seed HTTP API.");
|
||||
}
|
||||
return groupedCommits;
|
||||
}
|
||||
|
||||
export const formatCommitTime = (t: number): string => {
|
||||
|
||||
Reference in New Issue
Block a user