Skip to content

Commit

Permalink
change status to 204 on not found
Browse files Browse the repository at this point in the history
  • Loading branch information
hannah-macdonald1 committed Nov 6, 2024
1 parent 16a40fb commit 5d332c5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
value: ${{ secrets.APS_NAMESPACE }}
commitChange: false

- name: 'YAML poke: Set APS namespace'
- name: 'YAML poke: Set build number'
uses: fjogeleit/yaml-update-action@v0.15.0
with:
valueFile: 'helm/values.yaml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('RequestPreparerService', () => {
expect(result.data).toEqual({});
});

it.each([[404], [500]])(
it.each([[500]])(
`Should return HttpException with matching status on axios error`,
async (status) => {
const spy = jest.spyOn(httpService, 'get').mockImplementation(() => {
Expand All @@ -142,6 +142,28 @@ describe('RequestPreparerService', () => {
},
);

it('Should return HttpException with status 204 on 404 from upstream', async () => {
const spy = jest.spyOn(httpService, 'get').mockImplementation(() => {
throw new AxiosError(
'Axios Error',
'404',
{} as InternalAxiosRequestConfig,
{},
{
data: {},
status: 404,
statusText: '',
headers: {} as RawAxiosRequestHeaders,
config: {} as InternalAxiosRequestConfig,
},
);
});
await expect(
service.sendGetRequest('url', {}, {}),
).rejects.toHaveProperty('status', 204);
expect(spy).toHaveBeenCalledTimes(1);
});

it('Should return HttpException with status 500 on bearer token undefined', async () => {
const spy = jest
.spyOn(tokenRefresherService, 'refreshUpstreamBearerToken')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ export class RequestPreparerService {
if (error instanceof AxiosError) {
this.logger.error(error.message, error.stack, error.cause);
if (error.status === 404) {
throw new HttpException(
{
status: HttpStatus.NOT_FOUND,
error: 'There is no data for the requested resource',
},
HttpStatus.NOT_FOUND,
{ cause: error },
);
throw new HttpException({}, HttpStatus.NO_CONTENT, { cause: error });
}
} else {
this.logger.error(error);
Expand Down

0 comments on commit 5d332c5

Please sign in to comment.