Validation.mjs 558 B

123456789101112131415161718192021222324252627282930
  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. export const parseReq = (req, schema) => {
  11. try {
  12. return parseReqBase(req, schema)
  13. } catch (err) {
  14. if (err instanceof ParamsError) {
  15. // convert into a NotFoundError that web understands
  16. throw new NotFoundError('Not found').withCause(err)
  17. }
  18. throw err
  19. }
  20. }
  21. export default {
  22. parseReq,
  23. z,
  24. zz,
  25. }