mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-12 09:36:20 +00:00
Ensured server version is properly parsed to avoid errors due to invalid semver
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import { createAction, handleActions } from 'redux-actions';
|
||||
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
|
||||
import { versionIsValidSemVer } from '../../utils/utils';
|
||||
|
||||
/* eslint-disable padding-line-between-statements */
|
||||
export const SELECT_SERVER = 'shlink/selectedServer/SELECT_SERVER';
|
||||
export const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
|
||||
|
||||
export const MIN_FALLBACK_VERSION = '1.0.0';
|
||||
export const MAX_FALLBACK_VERSION = '999.999.999';
|
||||
export const LATEST_VERSION_CONSTRAINT = 'latest';
|
||||
/* eslint-enable padding-line-between-statements */
|
||||
|
||||
const initialState = null;
|
||||
@@ -15,7 +20,10 @@ export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serve
|
||||
|
||||
const selectedServer = findServerById(serverId);
|
||||
const { health } = await buildShlinkApiClient(selectedServer);
|
||||
const { version } = await health().catch(() => ({ version: '1.0.0' }));
|
||||
const version = await health()
|
||||
.then(({ version }) => version === LATEST_VERSION_CONSTRAINT ? MAX_FALLBACK_VERSION : version)
|
||||
.then((version) => !versionIsValidSemVer(version) ? MIN_FALLBACK_VERSION : version)
|
||||
.catch(() => MIN_FALLBACK_VERSION);
|
||||
|
||||
dispatch({
|
||||
type: SELECT_SERVER,
|
||||
|
||||
Reference in New Issue
Block a user