Skip to content

Commit

Permalink
Update error responses from external source/event end-points
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephVolosin committed Nov 19, 2024
1 parent 3fbecf9 commit 48cb21c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/packages/external-event/external-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ async function uploadExternalEventType(req: Request, res: Response) {
if (!schemaIsValid) {
throw new Error("Schema was not a valid JSON Schema.");
}
} catch (e) {
logger.error(`POST /uploadExternalEventType: ${(e as Error).message}`);
} catch (error) {
logger.error((error as Error).message);
res.status(500);
res.send(`POST /uploadExternalEventType: ${(e as Error).message}`);
res.send((error as Error).message);

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
return;
}

Expand All @@ -49,10 +49,10 @@ async function uploadExternalEventType(req: Request, res: Response) {
if (attribute_schema["title"] === undefined || attribute_schema.title !== external_event_type_name) {
throw new Error("Schema title does not match provided external event type name.")
}
} catch (e) {
logger.error(`POST /uploadExternalEventType: ${(e as Error).message}`);
} catch (error) {
logger.error((error as Error).message);
res.status(500);
res.send(`POST /uploadExternalEventType: ${(e as Error).message}`);
res.send((error as Error).message);
return;
}

Expand Down
27 changes: 12 additions & 15 deletions src/packages/external-source/external-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ async function uploadExternalSourceType(req: Request, res: Response) {
if (!schemaIsValid) {
throw new Error("Schema was not a valid JSON Schema.");
}
} catch (e) {
logger.error(`POST /uploadExternalSourceType: ${(e as Error).message}`);
} catch (error) {
res.status(500);
res.send(`POST /uploadExternalSourceType: ${(e as Error).message}`);
res.send((error as Error).message);

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
return;
}

Expand All @@ -60,20 +59,19 @@ async function uploadExternalSourceType(req: Request, res: Response) {
if (attribute_schema["title"] === undefined || attribute_schema.title !== external_source_type_name) {
throw new Error("Schema title does not match provided external source type name.")
}
} catch (e) {
logger.error(`POST /uploadExternalSourceType: ${(e as Error).message}`);
} catch (error) {
res.status(500);
res.send(`POST /uploadExternalSourceType: ${(e as Error).message}`);
res.send((error as Error).message);
return;
}

// Run the Hasura migration for creating an external source type (and inserting allowed event types)
const externalSourceTypeInput: ExternalSourceTypeInsertInput = {
attribute_schema: attribute_schema,
name: external_source_type_name,
}

const response = await fetch(GQL_API_URL, {
const response = await fetch(GQL_API_URL, {
body: JSON.stringify({
query: gql.CREATE_EXTERNAL_SOURCE_TYPE,
variables: { sourceType: externalSourceTypeInput },
Expand Down Expand Up @@ -126,9 +124,9 @@ async function uploadExternalSource(req: Request, res: Response) {
if (sourceIsValid) {
logger.info(`POST /uploadExternalSource: Source's formatting is valid per basic schema validation.`);
} else {
logger.error(`POST /uploadExternalSource: Source's formatting is invalid per basic schema validation:\n${JSON.stringify(compiledExternalSourceSchema.errors)}`);
logger.error("POST /uploadExternalSource: Source's formatting is invalid per basic schema validation");
res.status(500);
res.send(`POST /uploadExternalSource: Source's formatting is invalid per basic schema validation:\n${JSON.stringify(compiledExternalSourceSchema.errors)}`);
res.send("Source's formatting is invalid per basic schema validation");
return;
}

Expand Down Expand Up @@ -159,7 +157,7 @@ async function uploadExternalSource(req: Request, res: Response) {
// source type does not exist!
logger.error(`POST /uploadExternalSource: Source type ${source_type_name} does not exist!`);
res.status(500);
res.send(`POST /uploadExternalSource: Source type ${source_type_name} does not exist!`);
res.send(`Source type ${source_type_name} does not exist!`);

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.
return;
}
}
Expand All @@ -172,7 +170,7 @@ async function uploadExternalSource(req: Request, res: Response) {
if (sourceSchema !== undefined) {
res.send(`POST /uploadExternalSource: Source's attributes are invalid:\n${JSON.stringify(sourceSchema.errors)}`);

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

JSON schema validation error
is reinterpreted as HTML without escaping meta-characters.
} else {
res.send(`POST /uploadExternalSource: Source's attributes are invalid`);
res.send(`Source's attributes are invalid`);
}
return;
}
Expand Down Expand Up @@ -218,10 +216,9 @@ async function uploadExternalSource(req: Request, res: Response) {
if (!eventAttributesAreValid) {
throw new Error(`External Event '${externalEvent.key}' does not have a valid set of attributes, per it's type's schema:\n${JSON.stringify(currentEventSchema.errors)}`);
}
} catch (e) {
logger.error(`POST /uploadExternalSource: ${(e as Error).message}`);
} catch (error) {
res.status(500);
res.send((e as Error).message);
res.send((error as Error).message);

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/packages/external-source/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default { // TODO: discuss upset for derivation group
createExternalSource: insert_external_source_one (
object: $source
) {
attributes
derivation_group_name,
end_time,
key,
Expand Down

0 comments on commit 48cb21c

Please sign in to comment.