diff --git a/src/core/client/auth/components/SignIn.tsx b/src/core/client/auth/components/SignIn.tsx index 1934d03a8..24f2cb2f3 100644 --- a/src/core/client/auth/components/SignIn.tsx +++ b/src/core/client/auth/components/SignIn.tsx @@ -28,20 +28,24 @@ interface FormProps { export interface SignInForm { onSubmit: OnSubmit; setView: (view: View) => void; - errorMessage: string; + error: string | null; } const SignIn: StatelessComponent = props => { + console.log(props); return (
{({ handleSubmit, submitting }) => ( - {props.errorMessage && {props.errorMessage}} Sign in to join the conversation - + {props.error && ( + + {props.error} + + )} ; setView: (view: View) => void; - errorMessage: string; + error: string | null; } const SignUp: StatelessComponent = props => { return ( - {props.errorMessage && {props.errorMessage}} + {!!props.error && {props.error}} {({ handleSubmit, submitting }) => ( @@ -48,7 +48,11 @@ const SignUp: StatelessComponent = props => { Sign up to join the conversation - + {props.error && ( + + {props.error} + + )} { - public state = { errorMessage: "" }; + public state = { error: null }; private setView = (view: View) => { this.props.setView({ view, @@ -31,15 +32,13 @@ class SignInContainer extends Component< }; private onSubmit: SignInForm["onSubmit"] = async (input, form) => { try { - const res = await this.props.signIn(input); - console.log(res); - // form.reset(); + await this.props.signIn(input); + form.reset(); } catch (error) { + this.setState({ error: error.message }); if (error instanceof BadUserInputError) { return error.invalidArgsLocalized; } - console.log(error); - this.setState({ errorMessage: `Error: ${error}` }); // tslint:disable-next-line:no-console console.error(error); } @@ -50,7 +49,7 @@ class SignInContainer extends Component< ); } diff --git a/src/core/client/auth/containers/SignUpContainer.tsx b/src/core/client/auth/containers/SignUpContainer.tsx index 299bc5c91..1a9f91a46 100644 --- a/src/core/client/auth/containers/SignUpContainer.tsx +++ b/src/core/client/auth/containers/SignUpContainer.tsx @@ -15,7 +15,7 @@ interface SignUpContainerProps { } interface SignUpContainerState { - errorMessage: string; + error: string | null; } export type View = "SIGN_IN"; @@ -24,7 +24,7 @@ class SignUpContainer extends Component< SignUpContainerProps, SignUpContainerState > { - public state = { errorMessage: "" }; + public state = { error: "" }; private setView = (view: View) => { this.props.setView({ view, @@ -32,15 +32,13 @@ class SignUpContainer extends Component< }; private onSubmit: SignUpForm["onSubmit"] = async (input, form) => { try { - const res = await this.props.signUp(input); - console.log("response", res); + await this.props.signUp(input); form.reset(); } catch (error) { - console.log("error", error); + this.setState({ error: error.message }); if (error instanceof BadUserInputError) { return error.invalidArgsLocalized; } - this.setState({ errorMessage: `Something ${error}` }); // tslint:disable-next-line:no-console console.error(error); } @@ -51,7 +49,7 @@ class SignUpContainer extends Component< ); } diff --git a/src/core/client/auth/mutations/SignInMutation.ts b/src/core/client/auth/mutations/SignInMutation.ts index 6a88b9313..16fbf52d4 100644 --- a/src/core/client/auth/mutations/SignInMutation.ts +++ b/src/core/client/auth/mutations/SignInMutation.ts @@ -17,6 +17,7 @@ export async function commit( window.close(); } catch (err) { postMessage.send("authError", err.toString(), window.opener); + throw Error(err.message); } } diff --git a/src/core/client/auth/mutations/SignOffMutation.ts b/src/core/client/auth/mutations/SignOffMutation.ts index dcaadfd8f..01aa38cf0 100644 --- a/src/core/client/auth/mutations/SignOffMutation.ts +++ b/src/core/client/auth/mutations/SignOffMutation.ts @@ -11,10 +11,14 @@ export async function commit( input: SignOffInput, { rest, localStorage }: TalkContext ) { - await signOff(rest, input); - // tslint:disable-next-line:no-console - console.log("Signing off"); - localStorage.removeItem("authToken"); + try { + await signOff(rest, input); + localStorage.removeItem("authToken"); + } catch (error) { + localStorage.removeItem("authToken"); + // tslint:disable-next-line:no-console + console.error("error", error); + } } export const withSignOffMutation = createMutationContainer("signOff", commit); diff --git a/src/core/client/auth/mutations/SignUpMutation.ts b/src/core/client/auth/mutations/SignUpMutation.ts index 68beaeae2..76e6442c2 100644 --- a/src/core/client/auth/mutations/SignUpMutation.ts +++ b/src/core/client/auth/mutations/SignUpMutation.ts @@ -17,6 +17,7 @@ export async function commit( window.close(); } catch (err) { postMessage.send("authError", err.toString(), window.opener); + throw Error(err.toString()); } } diff --git a/src/core/client/framework/lib/errors/exceptionError.ts b/src/core/client/framework/lib/errors/exceptionError.ts new file mode 100644 index 000000000..16e79eaa6 --- /dev/null +++ b/src/core/client/framework/lib/errors/exceptionError.ts @@ -0,0 +1,4 @@ +export interface ExceptionError { + message: string; + stack: string; +} diff --git a/src/core/client/framework/lib/errors/index.ts b/src/core/client/framework/lib/errors/index.ts index 85539f649..2d58d8d08 100644 --- a/src/core/client/framework/lib/errors/index.ts +++ b/src/core/client/framework/lib/errors/index.ts @@ -2,4 +2,6 @@ export { default as NetworkError } from "./networkError"; export { default as UnknownServerError } from "./unknownServerError"; export { default as BadUserInputError } from "./badUserInputError"; export { default as GraphQLError } from "./graphqlError"; +export { default as ExceptionError } from "./exceptionError"; + export * from "./graphqlError"; diff --git a/src/core/client/framework/lib/rest.ts b/src/core/client/framework/lib/rest.ts index 975c7e282..b071aedb4 100644 --- a/src/core/client/framework/lib/rest.ts +++ b/src/core/client/framework/lib/rest.ts @@ -18,6 +18,11 @@ const buildOptions = (inputOptions: RequestInit = {}) => { }; const handleResp = async (res: Response) => { + if (res.status === 404) { + const response = await res.text(); + throw new Error(response); + } + if (!res.ok) { const response = await res.json(); throw new Error(response.error); @@ -41,7 +46,7 @@ export class RestClient { this.tokenGetter = tokenGetter; } - public fetch(path: string, options: PartialRequestInit): Promise { + public async fetch(path: string, options: PartialRequestInit): Promise { let opts = options; if (this.tokenGetter) { opts = merge({}, options, { @@ -50,10 +55,7 @@ export class RestClient { }, }); } - return fetch(`${this.uri}${path}`, buildOptions(opts)) - .then(handleResp) - .catch(err => { - throw Error(err); - }); + const response = await fetch(`${this.uri}${path}`, buildOptions(opts)); + return handleResp(response); } }