Skip to content

Commit

Permalink
Merge branch 'main' into fix-get-producer-keychains
Browse files Browse the repository at this point in the history
  • Loading branch information
Carminepo2 authored Sep 30, 2024
2 parents ae4919c + 6679728 commit 3801e87
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packages/backend-for-frontend/src/routers/catalogRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { makeApiProblem } from "../model/errors.js";
import { fromBffAppContext } from "../utilities/context.js";
import {
bffGetCatalogErrorMapper,
createEServiceDocumentErrorMapper,
emptyErrorMapper,
exportEServiceDescriptorErrorMapper,
importEServiceErrorMapper,
} from "../utilities/errorMappers.js";
import { config } from "../config/config.js";
import { toEserviceCatalogProcessQueryParams } from "../api/catalogApiConverter.js";
Expand Down Expand Up @@ -361,7 +364,7 @@ const catalogRouter = (
} catch (error) {
const errorRes = makeApiProblem(
error,
emptyErrorMapper,
createEServiceDocumentErrorMapper,
ctx.logger,
`Error creating eService document of kind ${req.body.kind} and name ${req.body.prettyName} for eService ${req.params.eServiceId} and descriptor ${req.params.descriptorId}`
);
Expand Down Expand Up @@ -663,7 +666,7 @@ const catalogRouter = (
} catch (error) {
const errorRes = makeApiProblem(
error,
bffGetCatalogErrorMapper,
exportEServiceDescriptorErrorMapper,
ctx.logger,
`Error exporting eservice ${req.params.eserviceId} with descriptor ${req.params.descriptorId}`
);
Expand Down Expand Up @@ -705,7 +708,7 @@ const catalogRouter = (
} catch (error) {
const errorRes = makeApiProblem(
error,
emptyErrorMapper,
importEServiceErrorMapper,
ctx.logger,
"Error importing eService"
);
Expand Down
41 changes: 41 additions & 0 deletions packages/backend-for-frontend/src/utilities/errorMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
HTTP_STATUS_UNAUTHORIZED,
HTTP_STATUS_FORBIDDEN,
HTTP_STATUS_TOO_MANY_REQUESTS,
HTTP_STATUS_BAD_REQUEST,
} = constants;

export const bffGetCatalogErrorMapper = (error: ApiError<ErrorCodes>): number =>
Expand Down Expand Up @@ -160,3 +161,43 @@ export const getProducerKeychainUsersErrorMapper = (
match(error.code)
.with("userNotFound", () => HTTP_STATUS_NOT_FOUND)
.otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR);

export const createEServiceDocumentErrorMapper = (
error: ApiError<ErrorCodes>
): number =>
match(error.code)
.with("eserviceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND)
.with(
"invalidInterfaceContentTypeDetected",
"invalidInterfaceFileDetected",
() => HTTP_STATUS_BAD_REQUEST
)
.otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR);

export const importEServiceErrorMapper = (
error: ApiError<ErrorCodes>
): number => {
// since verifyAndCreateEServiceDocument is shared, they throw the same errors
const baseMapperResult = createEServiceDocumentErrorMapper(error);

if (baseMapperResult === HTTP_STATUS_INTERNAL_SERVER_ERROR) {
return match(error.code)
.with(
"notValidDescriptor",
"invalidZipStructure",
() => HTTP_STATUS_BAD_REQUEST
)
.otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR);
}

return baseMapperResult;
};

export const exportEServiceDescriptorErrorMapper = (
error: ApiError<ErrorCodes>
): number =>
match(error.code)
.with("eserviceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND)
.with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST)
.with("invalidEserviceRequester", () => HTTP_STATUS_FORBIDDEN)
.otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR);
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ export const verifyAndCreateImportedDoc = async (
// eslint-disable-next-line max-params
): Promise<void> => {
const entry = entriesMap.get(doc.path);

const mimeType = mime.getType(doc.path) || "application/octet-stream";
if (entry === undefined) {
if (!entry) {
throw genericError("Invalid file");
}

const mimeType = mime.getType(doc.path) || "application/octet-stream";

const file = new File([entry.getData()], doc.path, {
type: mimeType,
});
Expand Down

0 comments on commit 3801e87

Please sign in to comment.