Skip to content

Commit

Permalink
improve grpc permission denied error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec committed Oct 21, 2020
1 parent 77dc2ef commit d7d8dbf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
16 changes: 16 additions & 0 deletions react/opentp-client/src/common/grpcUtilities.tsx
Original file line number Diff line number Diff line change
@@ -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
}
}
8 changes: 6 additions & 2 deletions react/opentp-client/src/components/Container/Container.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";



Expand All @@ -41,6 +42,7 @@ enum Views {




export default class Container extends React.Component<any, ContainerState> {


Expand Down Expand Up @@ -170,9 +172,11 @@ export default class Container extends React.Component<any, ContainerState> {
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")
}
Expand Down
6 changes: 5 additions & 1 deletion react/opentp-client/src/components/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -113,7 +114,10 @@ export default class Login extends React.Component<Props, State> {
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);
Expand Down
18 changes: 9 additions & 9 deletions react/opentp-client/src/components/OrderTicket/OrderTicket.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -508,9 +509,12 @@ export default class OrderTicket extends React.Component<OrderTicketProps, Order

this.executionVenueService.modifyOrder(modifyParams, Login.grpcContext.grpcMetaData, (err: Error) => {
if (err) {
let msg = "error whilst modifying order:" + err.message

let msg = getGrpcErrorMessage(err, "Failed to modify order")

log.error(msg)
alert(msg)

}
})
} else {
Expand Down Expand Up @@ -551,14 +555,10 @@ export default class OrderTicket extends React.Component<OrderTicketProps, Order
this.executionVenueService.createAndRouteOrder(croParams, Login.grpcContext.grpcMetaData, (err: Error,
response: OrderId) => {
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())
Expand Down

0 comments on commit d7d8dbf

Please sign in to comment.