Skip to content

Commit

Permalink
refactor(ui): migrate usage of client write API
Browse files Browse the repository at this point in the history
Part of #14482
  • Loading branch information
chnn committed Aug 2, 2019
1 parent e395f0e commit 56d1f43
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ui/src/dataLoaders/actions/dataLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ILabelProperties,
} from '@influxdata/influx'
import {createAuthorization} from 'src/authorizations/apis'
import {postWrite} from 'src/client'

// Utils
import {createNewPlugin} from 'src/dataLoaders/utils/pluginConfigs'
Expand Down Expand Up @@ -46,7 +47,6 @@ import {
TelegrafConfigCreationSuccess,
writeLimitReached,
} from 'src/shared/copy/notifications'
import {RATE_LIMIT_ERROR_STATUS} from 'src/cloud/constants/index'

type GetState = () => AppState

Expand Down Expand Up @@ -552,16 +552,20 @@ export const writeLineProtocolAction = (
) => async dispatch => {
try {
dispatch(setLPStatus(RemoteDataState.Loading))
await client.write.create(org, bucket, body, {precision})
dispatch(setLPStatus(RemoteDataState.Done))
} catch (error) {
const errorMessage = _.get(error, 'response.data.message', '')
console.error(errorMessage || error)
dispatch(setLPStatus(RemoteDataState.Error, errorMessage))

if (error.response.status === RATE_LIMIT_ERROR_STATUS) {
const resp = await postWrite({data: body, query: {org, bucket, precision}})

if (resp.status === 204) {
dispatch(setLPStatus(RemoteDataState.Done))
} else if (resp.status === 429) {
dispatch(notify(writeLimitReached()))
dispatch(setLPStatus(RemoteDataState.Error))
} else {
throw new Error(_.get(resp, 'data.message', 'Failed to write data'))
}
} catch (error) {
console.error(error)
dispatch(setLPStatus(RemoteDataState.Error, error.message))
}
}

Expand Down

0 comments on commit 56d1f43

Please sign in to comment.