Files
zkldi_Tachi/server/src/utils/prudence.ts
T
zkldi cad860413e fix: make all tests pass
I'm sorry for how disgustingly large all of these commits are. I promise
that this is the last time something this disgusting will happen.

This is a mono-patch for various things that were broken by the major
refactor. It's mostly things like error messages now being different
(and tests failing as a result).

Some notable fixes include me accidentally deleting the entire DELETE
api-tokens endpoint (lol), and timeAchieved: 0 in batch-manual not
coercing to null anymore. It appears the behaviour was intentional for
some reason. I'm not sure why though.
2022-05-31 17:56:14 +01:00

18 lines
596 B
TypeScript

import p from "prudence";
import type { PrudenceError, ValidSchemaValue } from "prudence";
export function FormatPrError(err: PrudenceError, foreword = "Error") {
const receivedText =
typeof err.userVal === "object" && err.userVal !== null
? ""
: ` | Received ${err.userVal} [type: ${
err.userVal === null ? "null" : typeof err.userVal
}]`;
return `${foreword}: ${err.keychain ?? "null"} | ${err.message}${receivedText}.`;
}
export const optNull = (v: ValidSchemaValue) => p.optional(p.nullable(v));
export const optNullFluffStrField = optNull(p.isBoundedString(3, 140));