Skip to content

Commit f732ff4

Browse files
author
Dennis Labordus
committed
Added check on NOT_FOUND to show correct message. (Tests)
Signed-off-by: Dennis Labordus <[email protected]>
1 parent e9a4648 commit f732ff4

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/compas-services/foundation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function handleError(error: Error): Promise<never> {
7070
}
7171

7272
export function isNotFoundError(reason: any): boolean {
73-
return (reason.type && reason.type === NOT_FOUND_ERROR);
73+
return (reason.type !== undefined && reason.type === NOT_FOUND_ERROR);
7474
}
7575

7676
export function createLogEvent(reason: any): void {

test/unit/compas-services/foundation.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import {expect} from "@open-wc/testing";
22

3-
import {processErrorMessage} from "../../../src/compas-services/foundation.js";
3+
import {
4+
isNotFoundError,
5+
NOT_FOUND_ERROR,
6+
processErrorMessage,
7+
SERVER_ERROR
8+
} from "../../../src/compas-services/foundation.js";
49

510
const errorBody =
611
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -19,13 +24,29 @@ describe('compas-services-foundation', () => {
1924
const result = await processErrorMessage(response);
2025
expect(result).to.be.equal(statusText);
2126
})
22-
2327
it('when there is a body in the response, the message is retrieved from the body', async () => {
2428
const expectedMessage = 'Name is not a correct name to be used later as filename. (CORE-8000)'
2529
const statusText = 'some status text';
2630
const response = new Response(errorBody, <ResponseInit>{statusText: statusText});
2731
const result = await processErrorMessage(response);
2832
expect(result).to.be.equal(expectedMessage);
33+
34+
})
35+
36+
it('when the error is caused by a status 404 then return true', () => {
37+
const reason = {type: NOT_FOUND_ERROR};
38+
const result = isNotFoundError(reason);
39+
expect(result).to.be.true;
40+
})
41+
it('when the error is caused by other status then return false', () => {
42+
const reason = {type: SERVER_ERROR};
43+
const result = isNotFoundError(reason);
44+
expect(result).to.be.false;
45+
})
46+
it('when no type of error found then return false', () => {
47+
const reason = {};
48+
const result = isNotFoundError(reason);
49+
expect(result).to.be.false;
2950
})
3051
});
3152

0 commit comments

Comments
 (0)