diff --git a/react/opentp-client/src/common/grpcUtilities.tsx b/react/opentp-client/src/common/grpcUtilities.tsx new file mode 100644 index 00000000..655f108d --- /dev/null +++ b/react/opentp-client/src/common/grpcUtilities.tsx @@ -0,0 +1,16 @@ +import { Error, StatusCode } from "grpc-web" + + +export function getGrpcErrorMessage( error : Error, prepend?: string) : string { + if( prepend ) { + prepend = prepend + ": " + } + + switch (error.code) { + case StatusCode.PERMISSION_DENIED: + return prepend + "Permission Denied" + + default: + return prepend + error.message + } +} \ No newline at end of file diff --git a/react/opentp-client/src/components/Container/Container.tsx b/react/opentp-client/src/components/Container/Container.tsx index 8923f2e1..a6a39644 100644 --- a/react/opentp-client/src/components/Container/Container.tsx +++ b/react/opentp-client/src/components/Container/Container.tsx @@ -1,7 +1,7 @@ import { Alignment, Button, Icon, Menu, MenuItem, Navbar, Popover, Position } from "@blueprintjs/core"; import FlexLayout, { Layout, Model, TabNode } from "flexlayout-react"; import "flexlayout-react/style/dark.css"; -import { Error } from "grpc-web"; +import { Error, StatusCode } from "grpc-web"; import React, { ReactNode } from 'react'; import log from 'loglevel'; import { ClientConfigServiceClient } from "../../serverapi/ClientconfigserviceServiceClientPb"; @@ -25,6 +25,7 @@ import ColumnChooser from "../TableView/ColumnChooser"; import ViewNameDialog from "./ViewNameDialog"; import { TicketController, ChildOrderBlotterController, OrderHistoryBlotterController, ExecutionsController, QuestionDialogController, ViewNameDialogController, ColumnChooserController } from "./Controllers"; import { ListingContext, OrderContext } from "./Contexts"; +import { getGrpcErrorMessage } from "../../common/grpcUtilities"; @@ -41,6 +42,7 @@ enum Views { + export default class Container extends React.Component { @@ -170,9 +172,11 @@ export default class Container extends React.Component { response: Empty) => { if (err) { - let msg = "error whilst cancelling all orders:" + err.message + + let msg = getGrpcErrorMessage(err, "Failed to cancel all orders") log.error(msg) alert(msg) + } else { log.debug("cancelled all orders") } diff --git a/react/opentp-client/src/components/Login/Login.tsx b/react/opentp-client/src/components/Login/Login.tsx index b499e56d..7d83aa83 100644 --- a/react/opentp-client/src/components/Login/Login.tsx +++ b/react/opentp-client/src/components/Login/Login.tsx @@ -8,6 +8,7 @@ import { LoginServiceClient } from "../../serverapi/LoginserviceServiceClientPb" import { LoginParams, Token } from "../../serverapi/loginservice_pb"; import Container from "../Container/Container"; import GrpcContextProvider from "../GrpcContextProvider"; +import { getGrpcErrorMessage } from "../../common/grpcUtilities"; export interface Props { @@ -113,7 +114,10 @@ export default class Login extends React.Component { response: Token) => { if (err) { - window.alert("Failed to login: " + err.message) + let msg = getGrpcErrorMessage(err, "Failed to login") + + log.error(msg) + alert(msg) } else { var deadline = new Date(); deadline.setSeconds(deadline.getSeconds() + 86400); diff --git a/react/opentp-client/src/components/OrderTicket/OrderTicket.tsx b/react/opentp-client/src/components/OrderTicket/OrderTicket.tsx index 318055e7..3e043f76 100644 --- a/react/opentp-client/src/components/OrderTicket/OrderTicket.tsx +++ b/react/opentp-client/src/components/OrderTicket/OrderTicket.tsx @@ -1,5 +1,5 @@ import { AnchorButton, Classes, Colors, Dialog, FormGroup, Intent, Label, NumericInput, MenuItem, Button } from '@blueprintjs/core'; -import { Error, StatusCode } from 'grpc-web'; +import { Error } from 'grpc-web'; import React, { CSSProperties } from 'react'; import { getListingLongName, getListingShortName, getTickSize } from '../../common/modelutilities'; import log from 'loglevel'; @@ -17,6 +17,7 @@ import { Select, ItemRenderer } from '@blueprintjs/select'; import VwapParamsPanel from './Strategies/VwapParams/VwapParamsPanel'; import { Destinations } from '../../common/destinations'; import { getStrategyDisplayName } from '../../common/strategydescriptions'; +import { getGrpcErrorMessage } from '../../common/grpcUtilities'; interface OrderTicketState { listing?: Listing, @@ -508,9 +509,12 @@ export default class OrderTicket extends React.Component { if (err) { - let msg = "error whilst modifying order:" + err.message + + let msg = getGrpcErrorMessage(err, "Failed to modify order") + log.error(msg) alert(msg) + } }) } else { @@ -551,14 +555,10 @@ export default class OrderTicket extends React.Component { if (err) { - let msg = "error whilst sending order:" + err.message - log.error(msg) - if (err.code === StatusCode.PERMISSION_DENIED) { - alert("permission denied") - } else { - alert(msg) - } + let msg = getGrpcErrorMessage(err, "Failed to send order") + log.error(msg) + alert(msg) } else { log.debug("create and route order created order with id:" + response.getOrderid())