Skip to content

Commit

Permalink
Merge pull request #318 from OnroerendErfgoed/hotfix/317_idservice_er…
Browse files Browse the repository at this point in the history
…ror_handling

#317 fix idservice
  • Loading branch information
yannickkuypers authored Jun 14, 2023
2 parents 8e8b922 + 11356df commit bb33fc0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 68 deletions.
2 changes: 1 addition & 1 deletion dist/commonjs/services/id-service.api-service.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions dist/commonjs/services/id-service.api-service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/commonjs/services/id-service.api-service.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions dist/native-modules/services/id-service.api-service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/native-modules/services/id-service.api-service.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oerelia",
"description": "Onroerend Erfgoed Aurelia component library",
"version": "0.24.1",
"version": "0.24.2",
"repository": {
"type": "git",
"url": "https://github.com/OnroerendErfgoed/oerelia.git"
Expand Down
36 changes: 15 additions & 21 deletions src/services/id-service.api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,34 @@ export class IdServiceApiService {
.withHeader('OpenAmSSOID', this.ssoToken)
.send()
.then(response => {
RestMessage.display({ result: MessageParser.parseHttpResponseMessage(response) });
RestMessage.display({result: MessageParser.parseHttpResponseMessage(response)});
if (response.isSuccess) {
return response.content;
}
});
}

public async getByUri<T>(uri: string, getSso: () => Promise<string>): Promise<IHttpResponse<T>> {
try {
const sso = await getSso();
const response = await this.http.createRequest(`${oeAppConfig.idServiceUrl + '/uris?uri=' + uri}`)
const sso = await getSso();
const response = await this.http.createRequest(`${oeAppConfig.idServiceUrl + '/uris?uri=' + uri}`)
.asGet()
.withHeader('Authorization', 'Bearer ' + sso)
.send() as IHttpResponse<IIdServiceResponse>;
.send() as IHttpResponse<IIdServiceResponse>;

if (response.content.location) {
try {
const locationResponse = await this.http.createRequest(response.content.location).asGet()
.withHeader('Authorization', 'Bearer ' + sso)
.send() as IHttpResponse<T>;

const content = locationResponse.content;
const etag = locationResponse.headers.get('ETag');
return { ...locationResponse, content: { ...content, etag } };
} catch (e) {
return;
}
}
} catch(e) {
if (!response.content.location) {
Message.error({
title: 'Fout',
message: 'Er ging iets mis bij het ophalen van uri: ' + uri
message: `Er ging iets mis bij het ophalen van uri: ${uri}`
});
return;
throw `Could not retrieve uri ${uri}`;
}

const locationResponse = await this.http.createRequest(response.content.location).asGet()
.withHeader('Authorization', 'Bearer ' + sso)
.send() as IHttpResponse<T>;

const content = locationResponse.content;
const etag = locationResponse.headers.get('ETag');
return {...locationResponse, content: {...content, etag}};
}
}

0 comments on commit bb33fc0

Please sign in to comment.