useMongocampError
Turns an error thrown by a MongoCamp API call into a displayable message.
const { describeError } = useMongocampError()
const { kind, message } = describeError(error, 'nuxtUiMongocamp.databases.errorLoad')kind | When |
|---|---|
network | The generated client threw a FetchError — the server is unreachable, or the browser hid a rejected response (this is what an expired session looks like) |
unauthorized | HTTP 401 |
notFound | HTTP 404 — the collection, document, file, user, role, job or index does not exist (any more); message "It does not exist (any more). It may have been deleted or renamed." (nuxtUiMongocamp.errors.notFound) |
forbidden | HTTP 403 — including a request the user has no grant for: the server answers that with a 401, which this module turns into a 403 before it reaches the error mapping (see useMongocampClientApi) |
other | Anything else; uses the error's own message, then the optional fallback i18n key, then nuxtUiMongocamp.errors.generic |
describeError is synchronous and only looks at the error object. The notAllowed and invalid kinds below come from describeServerError.
describeServerError
const { describeServerError } = useMongocampError()
const { kind, message } = await describeServerError(error, 'nuxtUiMongocamp.roles.errorDelete')The server sends CORS headers on every error, so the response body { code, msg } is readable. describeServerError reads it (one clone of the response, best effort) and says what the server said:
kind | When | Message |
|---|---|---|
notAllowed | code 4031 — the server refuses an operator ($function, $out, $merge, $accumulator, $where, $currentOp) | "The server does not allow the operator $function." — not a missing permission, although the status is 403 |
invalid | HTTP 400 with issues (server 2.3: a declared schema, a before-hook or the collection's validator refused the document) | "The document is not valid: name: is required; qty: must be at least 1" — the first five fields, then "and n more"; issues ({ path, message }[]) is on the result |
invalid | HTTP 400 with a message (a filter or body the server rejects) | the server's message |
notFound | HTTP 404 with a message ("could not find document", "the collection … does not exist") | the server's message |
other | code 4092 (409, server 2.3: a versioned declared collection was changed since the document was read) | "Someone else changed this document since it was loaded. …" |
other | any other status ≥ 400 with a message (a 500, a 409) | the server's message |
network, unauthorized, forbidden | unchanged | the fixed messages above (a plain 403 stays "no permission") |
Anything it cannot read — no response, a non-JSON body (a proxy's 503), no msg — falls back to describeError. The message never contains the database server's address: MongoDB's own text is extracted from a failed command (parseServerError) and every host:port is removed. The reading itself is readServerError in utils/serverError.ts.
Messages come from the nuxtUiMongocamp.errors.* locale keys (English and German). MongocampErrorAlert, the aggregation builder, the import wizard, the document save/delete dialogs of MongocampCollectionData and the delete/clone/save dialogs of the users, roles, jobs and grants components use describeServerError.
Server 2.5
tooLarge: a413(BODY_MAX_BYTES,GRIDFS_UPLOAD_MAX_BYTES,IMPORT_MAX_BYTES). Server 2.6 codes get their own message indescribeServerError:4131body (errors.tooLargeBody),4132upload (tooLargeUpload),4133import (tooLargeImport); another 413 keeps the server's text, which names the limit (tooLargeDetail).requestId: a 5xx description carries the answer'sx-request-id. The generic text of an unexpected error (INTERNAL_ERROR_MESSAGE) becomeserrors.internal; a database error keeps its message.- A refused filter operator (
$where,$function,$accumulatorin a filter or update, 403/4031) isnotAllowedwith the operator, like a refused aggregation stage.
Server 2.10 / 2.11
kind | When | Message |
|---|---|---|
rateLimited | 429 (RATE_LIMIT_LOGIN / RATE_LIMIT_REQUESTS, code 4291) — also from describeError | "… Try again in 7 s." with retryAfter (seconds, from Retry-After); without the header the text without a time. An external server must expose Retry-After through CORS_HEADERS_EXPOSED for the browser to read it |
accessDenied | code 4033 (403): an access rule or a field rule of a declared collection, or drafts=true without the write grant | "The access rules of this collection do not allow this." / "You may not read the field salary, …" / "You may not change these fields: salary" (issues on the result) / "Working copies (drafts) …" — a missing grant stays forbidden |
unsupportedType | 415: code 4151 (a declared bucket's types, checked by content) or 4152 (an image variant of a file that is no image) | "The bucket only accepts these types of file: image/png, text/plain." / "The file is not an image, …" |
linkInvalid / linkExpired | a signed file link: 403 code 4034 (changed or revoked) / 410 | "The link is not valid …" / "The link has expired." |
dependencyMissing | 501 code 5013 (image variants without sharp) | names the package; no request id |
tooLarge | 413 code 4134: a batch over 1000 operations | errors.tooLargeBatch |
Server 3.0
kind | When | Message |
|---|---|---|
unauthorized | 401 code 4013 (disabled account) / 4014 (a refresh token used twice — the session was ended) | says why; Log in again stays |
emailUnverified | 403 code 4035 (AUTH_REQUIRE_VERIFIED_EMAIL) | "The e-mail address is not confirmed yet. …" |
emailTaken | 409 code 4093 | "Another user already has this e-mail address." |
authLinkInvalid | 400 code 4403: a used, expired or unknown verification/reset/invitation/login link or code | "… Ask for a new one." |
busy | 503 code 5031: image variants busy | "Try again in a moment." (no request id) |
MongocampLogin names a disabled account and an unverified address (both only after the right password).
MongocampErrorAlert keeps Retry disabled and counts down while retryAfter runs. MongocampCollectionData treats a 4033 on a filtered request that names an unreadable field like a rejected filter (Clear filters): the server's fields/detail still lists fields a field rule hides, so the filter builder can offer one.