这是indexloc提供的服务,不要输入任何密码
Skip to content

Customise responseValidator #2104

@mrlubos

Description

@mrlubos

@mrlubos would it be possible to customise the responseValidator ?
Currently it generates a :

responseValidator: async (data) => {
  return await zXXXResponse.parseAsync(data);
},

but I want the request to succeed and just log it / show a notification in dev mode, but currently it is not possible, because in the client, the request config is always applied, maybe the request could just transport the zod schema,

      responseType: 'json',
      schema: zXXXResponse,
      url: '/XXX',

and the client could be :

if (opts.responseValidator) {
  await opts.responseValidator(data, schema);
}

and the default responseValidator could be :

responseValidator: async (data, schema) => {
  return await schema.parseAsync(data);
},

so we could do

responseValidator: async (data, schema) => {
  const result = await schema.safeParseAsync(data);
  console.log(result);
  notify(result);
},

Originally posted by @amarant in #876 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions