diff --git a/packages/search/src/elasticsearch/dbhelper.ts b/packages/search/src/elasticsearch/dbhelper.ts index 61b3b7a00f2..49bb8c886f3 100644 --- a/packages/search/src/elasticsearch/dbhelper.ts +++ b/packages/search/src/elasticsearch/dbhelper.ts @@ -17,20 +17,27 @@ export const indexComposition = async ( } catch (err) { // tslint:disable-next-line:no-console console.log(err) + throw err } } export const updateComposition = async (id: string, body: ICompositionBody) => { - const response = await client.update({ - index: 'ocrvs', - type: 'compositions', - id, - body: { - doc: body - } - }) + try { + const response = await client.update({ + index: 'ocrvs', + type: 'compositions', + id, + body: { + doc: body + } + }) - return response + return response + } catch (err) { + // tslint:disable-next-line:no-console + console.log(err) + throw err + } } export const searchComposition = async (body: ICompositionBody) => { @@ -46,6 +53,7 @@ export const searchComposition = async (body: ICompositionBody) => { } catch (err) { // tslint:disable-next-line:no-console console.log(err) + return null } } @@ -66,5 +74,6 @@ export const searchByCompositionId = async (compositionId: string) => { } catch (err) { // tslint:disable-next-line:no-console console.log(err) + return null } } diff --git a/packages/search/src/elasticsearch/utils.ts b/packages/search/src/elasticsearch/utils.ts index 7c91337e23a..236a14112de 100644 --- a/packages/search/src/elasticsearch/utils.ts +++ b/packages/search/src/elasticsearch/utils.ts @@ -68,13 +68,9 @@ export async function detectDuplicates( } export async function getCreatedBy(compositionId: string) { - let results - try { - results = await searchByCompositionId(compositionId) - } catch (error) { - console.log(error) - } + const results = await searchByCompositionId(compositionId) const result = + results && results.hits.hits && (results.hits.hits[0] && (results.hits.hits[0]._source as ICompositionBody)) @@ -83,9 +79,9 @@ export async function getCreatedBy(compositionId: string) { function findDuplicateIds( compositionIdentifier: string, - results: SearchResponse<{}> + results: SearchResponse<{}> | null ) { - const hits = results.hits.hits + const hits = (results && results.hits.hits) || [] return hits .filter( hit =>