zodios icon indicating copy to clipboard operation
zodios copied to clipboard

Add an option to disable exceptions

Open ecyrbe opened this issue 2 years ago • 5 comments

Today for error handling, since we use exceptions, we need to use error handling helpers (ie isErrorFromAlias and isErrorFromPath) to check errors safely. To improve error handling, we could also have the hability to disable exceptions and then return an object encapsulating the result. This way, we can directly return a typed error without requiring to use a helper.

const client = new Zodios(baseurl, myApi, { enableExceptions: false } );
const { data: users, error } = await client.getUsers();
if( error ) {
  // typed error
}

ecyrbe avatar Feb 07 '23 22:02 ecyrbe

For quick and dirty code, sometimes I just want the type hint without the full validation as a API is known to be wrong. I'd like a quick way to disable the run time validation while still having hints too. Would this solve for that?

tonyxiao avatar Mar 03 '23 09:03 tonyxiao

Not exactly, your use case would require to also handle data extraction from zodiosError. This proposal does not handle this use case. But if it's easy to add, we could add it to the todo list

ecyrbe avatar Mar 03 '23 11:03 ecyrbe

yea would love that. Right now if response does not pass validation then i'm completely stuck (other than manually modifying generated code, as wee use openapi-zod-client)

tonyxiao avatar Mar 04 '23 01:03 tonyxiao

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 03 '23 09:04 stale[bot]

For quick and dirty code, sometimes I just want the type hint without the full validation as a API is known to be wrong. I'd like a quick way to disable the run time validation while still having hints too. Would this solve for that?

I think you can get just type hint with { validate:"none" }

michael-land avatar Apr 07 '23 15:04 michael-land