Validation.mjs 628 B

12345678910111213141516171819202122232425262728293031323334
  1. // @ts-check
  2. import { NotFoundError } from '../Features/Errors/Errors.js'
  3. import {
  4. parseReq as parseReqBase,
  5. z,
  6. zz,
  7. ParamsError,
  8. } from '@overleaf/validation-tools'
  9. export { z, zz } from '@overleaf/validation-tools'
  10. /**
  11. * @param {any} req
  12. * @param {any} schema
  13. */
  14. export const parseReq = (req, schema) => {
  15. try {
  16. return parseReqBase(req, schema)
  17. } catch (/** @type {any} */ err) {
  18. if (err instanceof ParamsError) {
  19. // convert into a NotFoundError that web understands
  20. throw new NotFoundError('Not found').withCause(err)
  21. }
  22. throw err
  23. }
  24. }
  25. export default {
  26. parseReq,
  27. z,
  28. zz,
  29. }