Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: process.env errors #494

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/account/utils/Helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const VARS_T0_CHECK = [
"BICONOMY_SDK_DEBUG",
"REACT_APP_BICONOMY_SDK_DEBUG",
"NEXT_PUBLIC_BICONOMY_SDK_DEBUG"
]

export const isDebugging = (): boolean => {
try {
// @ts-ignore
return VARS_T0_CHECK.some(
(key) => process?.env?.[key]?.toString() === "true"
)
} catch (e) {
return false
}
}
5 changes: 4 additions & 1 deletion src/account/utils/HttpRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ export async function sendRequest<T>(
{ url, method, body }: HttpRequest,
service: Service
): Promise<T> {
const stringifiedBody = JSON.stringify(body)
Logger.log(`${service} RPC Request`, { url, body: stringifiedBody })

const response = await fetch(url, {
method,
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(body)
body: stringifiedBody
})

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
Expand Down
8 changes: 3 additions & 5 deletions src/account/utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* @param {any} message Message to be logged
*/

import { isDebugging } from "./Helpers"

// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
class Logger {
// By default, the logger is not in debug mode.
static isDebug: boolean = [
"BICONOMY_SDK_DEBUG",
"REACT_APP_BICONOMY_SDK_DEBUG",
"NEXT_PUBLIC_BICONOMY_SDK_DEBUG"
].some((key) => process?.env?.[key]?.toString() === "true")
static isDebug: boolean = isDebugging()

/**
* \x1b[0m is an escape sequence to reset the color of the text
Expand Down
Loading