Skip to content

Commit

Permalink
frontend: Add backend server error (#813)
Browse files Browse the repository at this point in the history
* Add backend server error

* uncomment dockerfile

* add key to msg
  • Loading branch information
tianjing-li authored Oct 16, 2024
1 parent 8dabb00 commit f428c55
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/interfaces/assistants_web/src/app/(auth)/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ const Login: React.FC = () => {

return (
<div className="flex flex-col items-center justify-center">
<Text
as="h1"
styleAs="h3"
>
<Text as="h1" styleAs="h3">
Log in
</Text>
<div className="mt-10 flex w-full flex-col items-center gap-1">
Expand Down
19 changes: 17 additions & 2 deletions src/interfaces/assistants_web/src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
import { createEnv } from '@t3-oss/env-nextjs';
import z from 'zod';

class ServerError extends Error {
constructor(message) {
super(message);
this.name = 'ServerError';
}
}

const readVariable = (key) => {
if (typeof window === 'undefined') return process.env[key];
return window.__ENV[key];
try {
if (typeof window === 'undefined'){
return process.env[key];
}
return window.__ENV[key];
} catch (err) {
throw new ServerError(
`${key} not configured, or the backend server is not running correctly.`
)
}
};

export const env = createEnv({
Expand Down
21 changes: 19 additions & 2 deletions src/interfaces/coral_web/src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@
import { createEnv } from '@t3-oss/env-nextjs';
import z from 'zod';


class ServerError extends Error {
constructor(message) {
super(message);
this.name = 'ServerError';
}
}

const readVariable = (key) => {
if (typeof window === 'undefined') return process.env[key];
return window.__ENV[key];
try {
if (typeof window === 'undefined'){
return process.env[key];
}
return window.__ENV[key];
} catch (err) {
throw new ServerError(
`${key} not configured, or the backend server is not running correctly.`
)
}
};


export const env = createEnv({
server: {
API_HOSTNAME: z.string().default('http://backend:8000'),
Expand Down

0 comments on commit f428c55

Please sign in to comment.