better error codes
Massimo Melina committed
Jan 26, 2023 at 16:42 UTC
75dea7292eb676507281b5b4a3d8844a7c15d4a2
2 files changed
+8
-7
src/api.accounts.ts
+2
-2
@@ -14,7 +14,7 @@ import {
14
setAccount
15
} from './perm'
16
import _ from 'lodash'
17
-import { HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_NOT_FOUND } from './const'
17
+import { HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_NOT_FOUND } from './const'
18
19
function prepareAccount(ac: Account | undefined) {
20
return ac && {
@@ -56,7 +56,7 @@ const apis: ApiHandlers = {
56
57
add_account({ username, ...rest }) {
58
if (getAccount(username))
59
- return new ApiError(HTTP_FORBIDDEN)
59
+ return new ApiError(HTTP_CONFLICT)
60
const acc = addAccount(username, rest)
61
return acc ? _.pick(acc, 'username') : new ApiError(HTTP_BAD_REQUEST)
62
},
src/api.vfs.ts
+6
-5
@@ -6,9 +6,10 @@ import { stat } from 'fs/promises'
6
import { ApiError, ApiHandlers } from './apiMiddleware'
7
import { dirname, join, resolve } from 'path'
8
import { dirStream, isWindowsDrive, objSameKeys } from './misc'
9
-import { exec } from 'child_process'
10
-import { promisify } from 'util'
11
-import { HTTP_BAD_REQUEST, HTTP_FORBIDDEN, IS_WINDOWS, HTTP_NOT_FOUND, HTTP_SERVER_ERROR, HTTP_CONFLICT } from './const'
9
+import {
10
+ IS_WINDOWS,
11
+ HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR, HTTP_CONFLICT, HTTP_NOT_ACCEPTABLE
12
+} from './const'
13
import { isMatch } from 'micromatch'
14
15
type VfsAdmin = {
@@ -79,7 +80,7 @@ const apis: ApiHandlers = {
80
if (!n)
81
return new ApiError(HTTP_NOT_FOUND, 'invalid under')
82
if (n.isTemp || !await nodeIsDirectory(n))
82
- return new ApiError(HTTP_FORBIDDEN, 'invalid under')
83
+ return new ApiError(HTTP_NOT_ACCEPTABLE, 'invalid under')
84
if (isWindowsDrive(source))
85
source += '\\' // slash must be included, otherwise it will refer to the cwd of that drive
86
const a = n.children || (n.children = [])
@@ -103,7 +104,7 @@ const apis: ApiHandlers = {
104
const parent = dirname(uri)
105
const parentNode = await urlToNodeOriginal(parent)
106
if (!parentNode)
106
- return HTTP_FORBIDDEN
107
+ return HTTP_NOT_ACCEPTABLE
108
const { children } = parentNode
109
if (!children) // shouldn't happen
110
return HTTP_SERVER_ERROR