Skip to content

Commit 0ffbbb3

Browse files
committed
fix(sdk): fix issue with sdk response handling
1 parent 58c3409 commit 0ffbbb3

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/infrastructure/services/portal-service.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ export class PortalService {
142142
private handlePortalGenerationErrors = async (error: unknown): Promise<string | NodeJS.ReadableStream> => {
143143
if (error instanceof UnauthorizedResponseError) {
144144
//401
145-
const body = await this.parseErrorResponse(error);
146-
return getMessageInRedColor(body.message ?? "Unauthorized access.");
145+
var unAuthError = error as UnauthorizedResponseError;
146+
return getMessageInRedColor(unAuthError.result?.message ?? "Authorization has been denied for this request.");
147147
} else if (error instanceof ProblemDetailsError) {
148148
//400 & 403
149-
const body = await this.parseErrorResponse(error);
150-
const message = body.errors[Object.keys(body.errors)[0]][0];
151-
return getMessageInRedColor(body.title + "\n- " + message);
149+
var probDetailsError = error as ProblemDetailsError;
150+
const message = (probDetailsError.result!.errors as Record<string, string[]>)?.['']?.[0];
151+
return getMessageInRedColor(probDetailsError.result!.title + "\n- " + message);
152152
} else if (error instanceof ApiError && error.statusCode === 422) {
153153
//422
154154
return error.body as NodeJS.ReadableStream;
@@ -177,18 +177,13 @@ export class PortalService {
177177
//TODO: Update the spec file to define different error code response types so that they can be handled here. Currently all failures go to the last else statement
178178
if (error instanceof UnauthorizedResponseError) {
179179
//401
180-
const body = await this.parseErrorResponse(error);
181-
return getMessageInRedColor(body.message ?? "Unauthorized access.");
180+
var unAuthError = error as UnauthorizedResponseError;
181+
return getMessageInRedColor(unAuthError.result?.message ?? "Authorization has been denied for this request.");
182182
} else if (error instanceof ProblemDetailsError) {
183183
//400 & 403
184-
const body = await this.parseErrorResponse(error);
185-
const message = body.errors[Object.keys(body.errors)[0]][0];
186-
return getMessageInRedColor(body.title + "\n- " + message);
187-
} else if (error instanceof ApiError && error.statusCode === 422) {
188-
const body = await this.parseErrorResponse(error);
189-
return getMessageInRedColor(
190-
`${body.message}`
191-
);
184+
var probDetailsError = error as ProblemDetailsError;
185+
const message = (probDetailsError.result!.errors as Record<string, string[]>)?.['']?.[0];
186+
return getMessageInRedColor(probDetailsError.result!.title + "\n- " + message);
192187
} else if (error instanceof InternalServerErrorResponseError) {
193188
//500
194189
const body = await this.parseErrorResponse(error);

0 commit comments

Comments
 (0)