Skip to content

Commit

Permalink
refactor: 调整生成数据请求发送方式支持错误处理 #21
Browse files Browse the repository at this point in the history
  • Loading branch information
eitbar committed Apr 19, 2020
1 parent 514a235 commit 7c44e79
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions src/react/components/pages/datasPage/datasPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,19 @@ export default class DatasPage extends React.Component<IDatasPageProps, IDatasPa

private handleGenerateClick = () => {
this.setState({dataGenerateLoaded: false, isGenerating: true,});
this.getDatasGenerate()
const endpointURL = url.resolve(
this.props.project.apiUriBase,
`/generate/pdf`,
);

const headers = {"Content-Type": "json", "cache-control": "no-cache" };
let jsonforsend = "";
let response;

try {
this.poll(() =>
ServiceHelper.postWithAutoRetry(
endpointURL, jsonforsend, { headers }, this.props.project.apiKey as string), 120000, 500)
.then((result) => {
let lastQuantity = this.state.dataQuantity;
this.setState({
Expand Down Expand Up @@ -361,6 +373,9 @@ export default class DatasPage extends React.Component<IDatasPageProps, IDatasPa
});

});
} catch (err) {
ServiceHelper.handleServiceError(err);
}
}

private handleDownloadClick = () => {
Expand Down Expand Up @@ -402,33 +417,6 @@ export default class DatasPage extends React.Component<IDatasPageProps, IDatasPa

}

private async getDatasGenerate(): Promise<any> {

const endpointURL = url.resolve(
this.props.project.apiUriBase,
`/generate/pdf`,
);

const headers = {"Content-Type": "json", "cache-control": "no-cache" };
let jsonforsend = "";
let response;
try {
response = await ServiceHelper.postWithAutoRetry(
endpointURL, jsonforsend, { headers }, this.props.project.apiKey as string);
} catch (err) {
ServiceHelper.handleServiceError(err);
}

const operationLocation = response.headers["operation-location"];

// Make the second REST API call and get the response.
return this.poll(() =>
ServiceHelper.getWithAutoRetry(
operationLocation, { headers }, this.props.project.apiKey as string), 120000, 500);

}


/**
* Poll function to repeatly check if request succeeded
* @param func - function that will be called repeatly
Expand Down

0 comments on commit 7c44e79

Please sign in to comment.