aptos-core icon indicating copy to clipboard operation
aptos-core copied to clipboard

[TS][SDK] Convert ApiError into AptosError

Open banool opened this issue 2 years ago • 7 comments

The node API, in the error case, invariably returns an AptosError, no matter what. The TS SDK however only returns an ApiError in the non 2xx case. This means the caller is responsible for taking the error body in the ApiError and converting it into an AptosError.

Apparently this is something our generator does not support natively: https://github.com/ferdikoomen/openapi-typescript-codegen/issues/728, https://github.com/ferdikoomen/openapi-typescript-codegen/issues/655. I suspect the best UX (though perhaps a bit messy) would be to postprocess the generated code. One cleanish option would be to add a function to ApiError like intoAptosError that tries to deserialize the error response body into an AptosError.

banool avatar Aug 25 '22 22:08 banool

We fork and modify it. https://github.com/aptos-labs/openapi-typescript-codegen. See this https://github.com/aptos-labs/aptos-core/pull/3385

jjleng avatar Aug 25 '22 22:08 jjleng

I think we avoid a fork if possible, that's a lot of effort to maintain. I see we already have one but this is a scary road to walk, our repo is already behind.

banool avatar Aug 25 '22 22:08 banool

I don't think that's a lot. Indexer is also using a forked diesel

jjleng avatar Aug 25 '22 22:08 jjleng

Yeah I don't love that either lol.

banool avatar Aug 25 '22 22:08 banool

If we do have a fork, we need to hold a high bar, we can't just hack up the codebase because we won't be able to stay on top of upstream.

banool avatar Aug 25 '22 22:08 banool

https://github.com/aptos-labs/aptos-core/pull/2851 is using the fork already. Otherwise, the hack was cumbersome. I had some post-processing and deleted that as it is harder to maintain the postprocessing scripts if there are many.

jjleng avatar Aug 25 '22 22:08 jjleng

Alright we'll see how it goes.

banool avatar Aug 25 '22 22:08 banool

This issue is stale because it has been open 45 days with no activity. Remove the stale label or comment - otherwise this will be closed in 15 days.

github-actions[bot] avatar Dec 20 '22 01:12 github-actions[bot]