Skip to content

Commit

Permalink
switch to boom wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Dec 3, 2019
1 parent 71ecee0 commit cd2afab
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 127 deletions.
45 changes: 20 additions & 25 deletions src/plugins/share/server/routes/goto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { CoreSetup, IRouter } from 'kibana/server';
import { schema } from '@kbn/config-schema';

import { handleShortUrlError } from './lib/short_url_error';
import { shortUrlAssertValid } from './lib/short_url_assert_valid';
import { ShortUrlLookupService } from './lib/short_url_lookup';

Expand All @@ -40,31 +39,27 @@ export const createGotoRoute = ({
params: schema.object({ urlId: schema.string() }),
},
},
async function(context, request, response) {
try {
const url = await shortUrlLookup.getUrl(request.params.urlId, {
savedObjects: context.core.savedObjects.client,
});
shortUrlAssertValid(url);
router.handleLegacyErrors(async function(context, request, response) {
const url = await shortUrlLookup.getUrl(request.params.urlId, {
savedObjects: context.core.savedObjects.client,
});
shortUrlAssertValid(url);

const uiSettings = context.core.uiSettings.client;
const stateStoreInSessionStorage = await uiSettings.get('state:storeInSessionStorage');
if (!stateStoreInSessionStorage) {
return response.redirected({
headers: {
location: http.basePath.prepend(url),
},
});
} else {
return response.redirected({
headers: {
location: http.basePath.prepend('/goto_LP/' + request.params.urlId),
},
});
}
} catch (err) {
return handleShortUrlError(response, err);
const uiSettings = context.core.uiSettings.client;
const stateStoreInSessionStorage = await uiSettings.get('state:storeInSessionStorage');
if (!stateStoreInSessionStorage) {
return response.redirected({
headers: {
location: http.basePath.prepend(url),
},
});
} else {
return response.redirected({
headers: {
location: http.basePath.prepend('/goto_LP/' + request.params.urlId),
},
});
}
}
})
);
};
62 changes: 0 additions & 62 deletions src/plugins/share/server/routes/lib/short_url_error.test.ts

This file was deleted.

28 changes: 0 additions & 28 deletions src/plugins/share/server/routes/lib/short_url_error.ts

This file was deleted.

20 changes: 8 additions & 12 deletions src/plugins/share/server/routes/shorten_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { IRouter } from 'kibana/server';
import { schema } from '@kbn/config-schema';

import { handleShortUrlError } from './lib/short_url_error';
import { shortUrlAssertValid } from './lib/short_url_assert_valid';
import { ShortUrlLookupService } from './lib/short_url_lookup';

Expand All @@ -38,16 +37,13 @@ export const createShortenUrlRoute = ({
body: schema.object({ url: schema.string() }, { allowUnknowns: false }),
},
},
async function(context, request, response) {
try {
shortUrlAssertValid(request.body.url);
const urlId = await shortUrlLookup.generateUrlId(request.body.url, {
savedObjects: context.core.savedObjects.client,
});
return response.ok({ body: { urlId } });
} catch (err) {
return handleShortUrlError(response, err);
}
}
router.handleLegacyErrors(async function(context, request, response) {
shortUrlAssertValid(request.body.url);
const urlId = await shortUrlLookup.generateUrlId(request.body.url, {
savedObjects: context.core.savedObjects.client,
});
throw new Error();
return response.ok({ body: { urlId } });
})
);
};

0 comments on commit cd2afab

Please sign in to comment.