Skip to content

Commit

Permalink
sdk: remove streamElement from presenter error streams #252
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Jul 25, 2023
1 parent 90e2624 commit 126f557
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/lib/infrastructure/presenter/list-dids-presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ListDIDsPresenter extends BaseStreamingPresenter<ListDIDsRe
return viewModel
}

streamErrorModelToViewModel(error: ListDIDsError, streamElement: string): ListDIDsViewModel {
streamErrorModelToViewModel(error: ListDIDsError): ListDIDsViewModel {
return {
status: 'error',
message: error.message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class ListSubscriptionsPresenter extends BaseStreamingPresenter<L
return viewModel;
}

streamErrorModelToViewModel(error: ListSubscriptionsError, streamElement: string): SubscriptionViewModel {
streamErrorModelToViewModel(error: ListSubscriptionsError): SubscriptionViewModel {
const viewModel: SubscriptionViewModel = getEmptySubscriptionViewModel();
viewModel.message = error.message;
viewModel.status = 'error';
Expand Down
17 changes: 0 additions & 17 deletions src/lib/sdk/postprocessing-pipeline-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,7 @@ export abstract class BaseStreamingPostProcessingPipelineElement<TRequestModel,
requestModel: requestModel,
responseModel: response,
})
// try {
// if (dto.status === 'error') {
// const errorModel: TErrorModel = this.handleGatewayError(dto)
// this.emit('error', errorModel)
// callback()
// }
// const { status, data } = this.validateDTO(dto)
// if(status === 'error') {
// this.emit('error', data)
// callback(data as Error)
// }
// const transformedResponseModel = this.transformResponseModel(responseModel, dto)
// callback(undefined, {
// requestModel: requestModel,
// responseModel: transformedResponseModel
// })
} catch (error: Error | any) {
// this.emit('Unknown error with Gateway Request: ', error)
const errorModel: TErrorModel = {
status: 'error',
message: `Unknown Error in pipeline element ${this.constructor.name}`,
Expand Down
9 changes: 6 additions & 3 deletions src/lib/sdk/presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export abstract class BaseStreamingPresenter<
* Convert an error that occurred for a given stream element to a view model.
* @param error An ErrorResponseModel that represents the error that occurred for a given stream element.
*/
abstract streamErrorModelToViewModel(error: TErrorModel, streamElement: string): TStreamViewModel
abstract streamErrorModelToViewModel(error: TErrorModel): TStreamViewModel

/**
* Presents a stream of response models.
Expand Down Expand Up @@ -156,12 +156,15 @@ export abstract class BaseStreamingPresenter<
this.streamResponseModelToViewModel(responseModel)
callback(null, JSON.stringify(viewModel))
} else {
const viewModel = this.streamErrorModelToViewModel(responseModel as unknown as TErrorModel, "Presenter")
const viewModel = this.streamErrorModelToViewModel(responseModel as unknown as TErrorModel)
callback(null, JSON.stringify(viewModel))
}
} catch (error) {
// If an error occurs while processing response or error models, we need to handle it here.
callback(error as Error)
callback(null, {
status: 'error',
message: `The presenter returned with an error while in pipeline element ${this.constructor.name}. Error: ${error}}`,
} as TStreamViewModel)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/sdk/primary-ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ export interface BaseStreamingOutputPort<TResponseModel extends BaseResponseMode
responseModel: TResponseModel,
): TStreamViewModel

streamErrorModelToViewModel(error: TErrorModel, streamElement: string): TStreamViewModel
streamErrorModelToViewModel(error: TErrorModel): TStreamViewModel
}
4 changes: 2 additions & 2 deletions test/sdk/fixtures/presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export class TestPresenter extends BaseStreamingPresenter<
BaseErrorResponseModel,
ViewModel
> {
streamErrorModelToViewModel(error: BaseErrorResponseModel, streamElement: string): ViewModel {
streamErrorModelToViewModel(error: BaseErrorResponseModel): ViewModel {
const viewModel: ViewModel = {
status: 'error',
title: 'failed: ' + error.message + ' for stream element: ' + streamElement,
title: 'failed: ' + error.message,
}
return viewModel
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ describe("Post Processing Streaming Pipeline Error Handling", () => {
})

await done
console.log(receivedData)
console.log(receivedData)
expect (receivedData).toEqual([
{
status: 'error',
title: 'failed: Failed to authenticate user',
},
{
status: 'error',
title: 'failed: Failed to authenticate user'
},
])

})
})
2 changes: 1 addition & 1 deletion test/sdk/stream-error-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ describe("Stream Error Handling", () => {
await done
expect(receivedData.length).toBe(3)
expect(receivedData[2].status).toBe('error')
expect(receivedData[2].title).toBe('failed: Failed to process data for stream element: Presenter')
expect(receivedData[2].title).toBe('failed: Failed to process data')
})
});

0 comments on commit 126f557

Please sign in to comment.