fix(server/errors): derive errors from BaseError (#3918)

This commit is contained in:
Iain Sproat
2025-01-30 18:15:56 +01:00
committed by GitHub
parent 46cf4e44eb
commit c59e6043bb
52 changed files with 278 additions and 98 deletions
@@ -34,6 +34,7 @@ import {
import {
CommitCreateError,
CommitDeleteError,
CommitNotFoundError,
CommitReceiveError,
CommitUpdateError
} from '@/modules/core/errors/commit'
@@ -47,6 +48,7 @@ import { BranchRecord, CommitRecord } from '@/modules/core/helpers/types'
import { EventBusEmit } from '@/modules/shared/services/eventBus'
import { ensureError, Roles } from '@speckle/shared'
import { has } from 'lodash'
import { BranchNotFoundError } from '@/modules/core/errors/branch'
export const markCommitReceivedAndNotifyFactory =
({ getCommit, saveActivity }: { getCommit: GetCommit; saveActivity: SaveActivity }) =>
@@ -301,10 +303,10 @@ export const updateCommitAndNotifyFactory =
const newBranch = await deps.getStreamBranchByName(streamId, newBranchName)
if (!newBranch || !branch) {
throw new Error("Couldn't resolve branch")
throw new BranchNotFoundError("Couldn't resolve branch")
}
if (!commit) {
throw new Error("Couldn't find commit")
throw new CommitNotFoundError("Couldn't find commit")
}
await deps.switchCommitBranch(commitId, newBranch.id, branch.id)
@@ -17,6 +17,7 @@ import {
PaginatedBranchCommitsParams
} from '@/modules/core/domain/commits/operations'
import { GetStreamBranchByName } from '@/modules/core/domain/branches/operations'
import { BranchNotFoundError } from '@/modules/core/errors/branch'
export const legacyGetPaginatedStreamCommitsFactory =
(deps: {
@@ -110,7 +111,8 @@ export const getBranchCommitsTotalCountByNameFactory =
branchName = branchName.toLowerCase()
const myBranch = await deps.getStreamBranchByName(streamId, branchName)
if (!myBranch) throw new Error(`Failed to find branch with name ${branchName}.`)
if (!myBranch)
throw new BranchNotFoundError(`Failed to find branch with name ${branchName}.`)
return deps.getBranchCommitsTotalCount({ branchId: myBranch.id })
}
@@ -123,7 +125,8 @@ export const getPaginatedBranchCommitsItemsByNameFactory =
branchName = branchName.toLowerCase()
const myBranch = await deps.getStreamBranchByName(streamId, branchName)
if (!myBranch) throw new Error(`Failed to find branch with name ${branchName}.`)
if (!myBranch)
throw new BranchNotFoundError(`Failed to find branch with name ${branchName}.`)
return deps.getPaginatedBranchCommitsItems({ branchId: myBranch.id, limit, cursor })
}