diff --git a/packages/api/src/user.js b/packages/api/src/user.js index ce432803e6..388075cfa6 100644 --- a/packages/api/src/user.js +++ b/packages/api/src/user.js @@ -1,6 +1,7 @@ import * as JWT from './utils/jwt.js' import { JSONResponse } from './utils/json-response.js' import { JWT_ISSUER } from './constants.js' +import { HTTPError } from './errors.js' /** * @typedef { _id: string, issuer: string } User @@ -210,7 +211,11 @@ export async function userUploadsDelete (request, env) { const user = request.auth.user._id const res = await env.db.deleteUpload(user, cid) - return new JSONResponse(res) + if (res) { + return new JSONResponse(res) + } + + throw new HTTPError('Upload not found', 404) } /** diff --git a/packages/db/index.js b/packages/db/index.js index 14eca63668..ffbb62566d 100644 --- a/packages/db/index.js +++ b/packages/db/index.js @@ -278,7 +278,7 @@ export class DBClient { .single() if (error) { - throw new DBError(error) + return undefined } return { diff --git a/packages/db/test/upload.spec.js b/packages/db/test/upload.spec.js index c77802fbfd..acfa761fed 100644 --- a/packages/db/test/upload.spec.js +++ b/packages/db/test/upload.spec.js @@ -190,13 +190,8 @@ describe('upload', () => { assert.strictEqual(deletedUpload.updated_at, deletedUpload.deleted_at) // Should fail to delete again - let error - try { - await client.deleteUpload(user._id, otherCid) - } catch (err) { - error = err - } - assert(error, 'should fail to delete upload again') + const wasDeletedAgain = await client.deleteUpload(user._id, otherCid) + assert.strictEqual(wasDeletedAgain, undefined, 'should fail to delete upload again') const finalUserUploads = await client.listUploads(user._id) assert(finalUserUploads, 'user upload deleted')