Skip to content

Commit

Permalink
Improve error handling versions / history
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Jul 26, 2023
1 parent 2440268 commit 5e91e27
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions browser/data-browser/src/routes/History/useVersions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Resource, Version, useStore } from '@tomic/react';
import { useState, useEffect } from 'react';
import { dedupeVersions } from './versionHelpers';
import { handleError } from '../../helpers/loggingHandlers';

export interface UseVersionsResult {
versions: Version[];
Expand All @@ -21,6 +22,7 @@ export function useVersions(resource: Resource): UseVersionsResult {
setVersions(dedupeVersions(history));
})
.catch(e => {
handleError(e);
setError(e);
})
.finally(() => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions browser/lib/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,24 @@ export class Resource {
const commitsCollection = await store.fetchResourceFromServer(
this.getCommitsCollection(),
);

if (commitsCollection.error) {
throw commitsCollection.error;
}

const commits = commitsCollection.get(properties.collection.members);

const builtVersions: Version[] = [];

let previousResource = new Resource(this.subject);

if (!commits) {
throw new Error(
`Couldn't find commits for ${this.getSubject()} in CommitCollection: ` +
this.getCommitsCollection(),
);
}

for (const commit of commits as unknown as string[]) {
const commitResource = await store.getResourceAsync(commit);
const parsedCommit = parseCommitResource(commitResource);
Expand Down

0 comments on commit 5e91e27

Please sign in to comment.