Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion hrm-domain/lambdas/search-index-consumer/payloadToIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
PayloadsByAccountSid,
PayloadsByIndex,
} from './messagesToPayloads';
import { type HrmAccountId, newErr, newOkFromData } from '@tech-matters/types';
import { type HrmAccountId, newErr, newOkFromData, isErr } from '@tech-matters/types';
import { HrmIndexProcessorError } from '@tech-matters/job-errors';

const handleIndexPayload =
Expand Down Expand Up @@ -90,6 +90,13 @@ const handleIndexPayload =
id: documentId.toString(),
});

if (isErr(result)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some debug logging here?

// bubble error if it's different from "not found", ignore otherwise
if (result.extraProperties?.statusCode !== 404) {
result.unwrap();
}
}

return {
accountSid,
indexType,
Expand Down
21 changes: 16 additions & 5 deletions packages/elasticsearch-client/src/deleteDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,34 @@
*/
import { DeleteResponse } from '@elastic/elasticsearch/lib/api/types';
import { PassThroughConfig } from './client';
import { newErr, newOk, TResult } from '@tech-matters/types';

export type DeleteDocumentExtraParams = {
id: string;
};

export type DeleteDocumentParams<T> = PassThroughConfig<T> & DeleteDocumentExtraParams;
export type DeleteDocumentResponse = DeleteResponse;
export type DeleteDocumentResponse = TResult<'DeleteDocumentError', DeleteResponse>;

export const deleteDocument = async <T>({
client,
id,
index,
}: DeleteDocumentParams<T>): Promise<DeleteDocumentResponse> => {
return client.delete({
index,
id,
});
try {
const response = await client.delete({
index,
id,
});

return newOk({ data: response });
} catch (error) {
return newErr({
error: 'DeleteDocumentError',
message: error instanceof Error ? error.message : String(error),
extraProperties: { ...(error as any)?.meta, originalError: error },
});
}
};

export default deleteDocument;
3 changes: 3 additions & 0 deletions packages/types/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type ErrorResult<TError> = ResultBase & {
status: 'error';
message: string;
error: TError;
extraProperties?: Record<string, any>;
readonly unwrap: () => never;
};

Expand All @@ -51,12 +52,14 @@ class ResultError<T extends ErrorResult<any>> extends Error {
export const newErr = <TError>({
message,
error,
extraProperties,
}: NewErrorResultParams<TError>): ErrorResult<TError> => {
return {
_tag: 'Result',
status: 'error',
message,
error,
extraProperties,
unwrap: function (this: ErrorResult<TError>) {
throw new ResultError(this);
},
Expand Down
Loading