-
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.
Merge pull request #3528 from osmosis-labs/stage
Publish Stage
- Loading branch information
Showing
17 changed files
with
285 additions
and
121 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
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
Oops, something went wrong.