-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
fix: improve postman logging and error parsing (#622)
* fix: improve postman logging and error parsing * fix: remove unnecessary casting
Showing
30 changed files
with
547 additions
and
338 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,11 +1,35 @@ | ||
export class BaseError extends Error { | ||
reason?: BaseError | Error | string; | ||
export type InferErrorType<T> = T extends Error | ||
? Error | ||
: T extends string | ||
? string | ||
: T extends number | ||
? number | ||
: T extends { message: string } | ||
? { message: string } | ||
: unknown; | ||
|
||
override name = "LineaSDKCoreError"; | ||
export class BaseError<T = unknown, M = unknown> extends Error { | ||
stack: string = ""; | ||
metadata?: M; | ||
error: InferErrorType<T>; | ||
|
||
constructor(message?: string) { | ||
super(); | ||
this.message = message || "An error occurred."; | ||
Error.captureStackTrace(this, this.constructor); | ||
constructor(error: T, metadata?: M) { | ||
const message = BaseError.getMessage(error); | ||
super(message); | ||
this.stack = error instanceof Error && error.stack ? error.stack : message; | ||
this.metadata = metadata; | ||
this.error = error as InferErrorType<T>; | ||
|
||
Object.setPrototypeOf(this, BaseError.prototype); | ||
} | ||
|
||
private static getMessage(error: unknown): string { | ||
if (typeof error === "string") return error; | ||
if (typeof error === "number") return `Error Code: ${error}`; | ||
if (error instanceof Error) return error.message; | ||
if (typeof error === "object" && error !== null && "message" in error) { | ||
return String(error.message); | ||
} | ||
return "Unknown error"; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,14 +1,8 @@ | ||
import { describe, it } from "@jest/globals"; | ||
import { BaseError } from "../BaseError"; | ||
import { serialize } from "../../utils/serialize"; | ||
import { makeBaseError } from "../utils"; | ||
|
||
describe("BaseError", () => { | ||
it("Should log error message when we only pass a short message", () => { | ||
expect(serialize(new BaseError("An error message."))).toStrictEqual( | ||
serialize({ | ||
name: "LineaSDKCoreError", | ||
message: "An error message.", | ||
}), | ||
); | ||
expect(makeBaseError("An error message.").message).toStrictEqual("An error message."); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { BaseError } from "./BaseError"; | ||
export { GasEstimationError, FeeEstimationError } from "./GasFeeErrors"; | ||
export { makeBaseError, isBaseError } from "./utils"; |
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,35 @@ | ||
import { isNativeError } from "util/types"; | ||
import { BaseError, InferErrorType } from "./BaseError"; | ||
|
||
/** | ||
* Converts an `unknown` value that was thrown into a `BaseError` object. | ||
* | ||
* @param value - An `unknown` value. | ||
* | ||
* @returns A `BaseError` object. | ||
*/ | ||
export const makeBaseError = <E, M>(value: E extends BaseError<E, M> ? never : E, metadata?: M): BaseError<E, M> => { | ||
if (isNativeError(value)) { | ||
return new BaseError(value, metadata); | ||
} else { | ||
try { | ||
return new BaseError( | ||
new Error(`${typeof value === "object" ? JSON.stringify(value) : String(value)}`), | ||
metadata, | ||
) as BaseError<E, M>; | ||
} catch { | ||
return new BaseError(new Error(`Unexpected value thrown: non-stringifiable object`), metadata) as BaseError<E, M>; | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Type guard to check if an `unknown` value is a `BaseError` object. | ||
* | ||
* @param value - The value to check. | ||
* | ||
* @returns `true` if the value is a `BaseError` object, otherwise `false`. | ||
*/ | ||
export const isBaseError = <E, M>(value: unknown): value is BaseError<InferErrorType<E>, M> => { | ||
return value instanceof BaseError && typeof value.stack === "string" && "metadata" in value && "error" in value; | ||
}; |
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