Skip to content

Commit fde30f4

Browse files
author
Rob Tjalma
authored
Merge pull request #97 from com-pas/fix-loading
When CoMPAS call fails react as if not in CoMPAS.
2 parents de4cf0f + 4ff0913 commit fde30f4

File tree

4 files changed

+5
-33
lines changed

4 files changed

+5
-33
lines changed

src/compas-editors/CompasVersions.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {get, translate} from 'lit-translate';
33
import {newLogEvent, newWizardEvent, Wizard} from "../foundation.js";
44

55
import {CompasSclDataService, SDS_NAMESPACE} from "../compas-services/CompasSclDataService.js";
6-
import {createLogEvent, isNotFoundError, NOT_FOUND_ERROR} from "../compas-services/foundation.js";
6+
import {createLogEvent} from "../compas-services/foundation.js";
77
import {getTypeFromDocName, updateDocumentInOpenSCD} from "../compas/foundation.js";
88
import {getElementByName, getOpenScdElement, styles} from './foundation.js';
99
import {addVersionToCompasWizard} from "../compas/CompasUploadVersion.js";
@@ -54,10 +54,8 @@ export default class CompasVersionsPlugin extends LitElement {
5454
.then(xmlResponse => {
5555
this.scls = Array.from(xmlResponse.querySelectorAll('Item') ?? []);
5656
})
57-
.catch(reason => {
58-
if (isNotFoundError(reason)) {
59-
this.scls = [];
60-
}
57+
.catch(() => {
58+
this.scls = [];
6159
});
6260
}
6361

src/compas-services/foundation.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ export function handleError(error: Error): Promise<never> {
6969
return Promise.reject({type: SERVER_ERROR, message: error.message});
7070
}
7171

72-
export function isNotFoundError(reason: any): boolean {
73-
return (reason.type !== undefined && reason.type === NOT_FOUND_ERROR);
74-
}
75-
7672
export function createLogEvent(reason: any): void {
7773
let message = reason.message;
7874
if (reason.status) {

src/compas/CompasExistsIn.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {property} from "lit-element";
33
import {LitElementConstructor, Mixin} from "../foundation.js";
44

55
import {CompasSclDataService} from "../compas-services/CompasSclDataService.js";
6-
import {isNotFoundError, NOT_FOUND_ERROR} from "../compas-services/foundation.js";
76
import {getTypeFromDocName} from "./foundation.js";
87

98
export type CompasExistsInElement = Mixin<typeof CompasExistsIn>;
@@ -32,10 +31,8 @@ export function CompasExistsIn<TBase extends LitElementConstructor>(Base: TBase)
3231
const docType = getTypeFromDocName(this.docName);
3332
this.callService(docType, this.docId)
3433
.then(() => this.existInCompas = true)
35-
.catch(reason => {
36-
if (isNotFoundError(reason)) {
37-
this.existInCompas = false;
38-
}
34+
.catch(() => {
35+
this.existInCompas = false;
3936
});
4037
} else {
4138
this.existInCompas = false;

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

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

33
import {
4-
isNotFoundError,
5-
NOT_FOUND_ERROR,
64
processErrorMessage,
7-
SERVER_ERROR
85
} from "../../../src/compas-services/foundation.js";
96

107
const errorBody =
@@ -32,21 +29,5 @@ describe('compas-services-foundation', () => {
3229
expect(result).to.be.equal(expectedMessage);
3330

3431
})
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;
50-
})
5132
});
5233

0 commit comments

Comments
 (0)