-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Deposit/Withdraw) Recommend Alloyed asset (#3535)
* fix quotable provider picking * skip: include counterparties of same variant * capture squid error * use zod for squid errors * i * return providers only for from asset * cleanup * catch parse errors * fix tests
- Loading branch information
Showing
7 changed files
with
136 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ApiClientError } from "@osmosis-labs/utils"; | ||
import { z } from "zod"; | ||
|
||
const SquidErrors = z.object({ | ||
errors: z.array( | ||
z.object({ | ||
path: z.string().optional(), | ||
errorType: z.string(), | ||
message: z.string(), | ||
}) | ||
), | ||
}); | ||
|
||
type SquidErrors = z.infer<typeof SquidErrors>; | ||
|
||
/** | ||
* Squid returns error data in the form of an errors object containing an array of errors. | ||
* This function returns the list of those errors, and sets the Error.message to a concatenation of those errors. | ||
* @returns list of error messages | ||
*/ | ||
export function getSquidErrors(error: ApiClientError): SquidErrors { | ||
try { | ||
const e = error as ApiClientError<SquidErrors>; | ||
const squidError = SquidErrors.parse(e.data); | ||
const msgs = squidError.errors.map( | ||
({ message }, i) => `${i + 1}) ${message}` | ||
); | ||
e.message = msgs.join(", "); | ||
return squidError; | ||
} catch (e) { | ||
if (e instanceof z.ZodError) { | ||
throw new Error("Squid error validation failed:" + e.errors.join(", ")); | ||
} | ||
throw new Error("Squid errors: An unexpected error occurred"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters