summaryrefslogtreecommitdiffstats
path: root/server/lib/httpresponse.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/httpresponse.js')
-rw-r--r--server/lib/httpresponse.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/server/lib/httpresponse.js b/server/lib/httpresponse.js
index cb4b216..c402e39 100644
--- a/server/lib/httpresponse.js
+++ b/server/lib/httpresponse.js
@@ -27,12 +27,25 @@ HttpResponse.successBatch = (action, type, count) => {
}
// ############################################################################
+// ############################## WARNING #####################################
+
+HttpResponse.warningBatch = (action, type, successfull, count) => {
+ const failed = count - successfull
+ let tmpType = type
+ if (failed > 1) tmpType += 's'
+ if (Array.isArray(type)) type = type[successfull === 1 ? 0 : 1]
+ else if (successfull !== 1) type += 's'
+ return new HttpResponse(200, action.toUpperCase() + '_MULTIPLE', `Warning: ${action} ${successfull}/${count} ${type}. ${failed} ${tmpType} failed.`, { successfull, count })
+}
+
+// ############################################################################
// ############################### ERROR ######################################
// General
HttpResponse.notFound = (id) => new HttpResponse(404, 'NOT_FOUND', 'ID ' + id + ' does not exist.')
HttpResponse.invalidId = (zeroAllowed) => new HttpResponse(400, 'INVALID_ID', 'ID has to be an integer' + (zeroAllowed ? '' : ' greater than 0') + '.')
HttpResponse.invalidBodyValue = (key, rule) => new HttpResponse(400, 'BAD_REQUEST', 'JSON body value for key "' + key + '" has to be ' + rule + '.')
+HttpResponse.noPermission = (id, permission) => new HttpResponse(403, 'NO_PERMISSION', 'Missing permission ' + permission + ' for object ' + id + '.')
// Authentication
HttpResponse.invalidToken = () => new HttpResponse(401, 'INVALID_TOKEN', 'The provided token is invalid.')