Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beter 404 for plots-tables #140

Merged
merged 7 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/general-services/pipeline-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const getPipelineStatus = async (experimentId, processName) => {
/* eslint-enable no-await-in-loop */

completedSteps = getStepsFromExecutionHistory(events);
logger.log(`ExecutionHistory for ARN ${executionArn}: ${events.length} events, ${completedSteps.length} completed steps`);
logger.log(`ExecutionHistory(${processName}) for ARN ${executionArn}: ${events.length} events, ${completedSteps.length} completed steps`);
}

const response = {
Expand Down
23 changes: 12 additions & 11 deletions src/api/routes/gem2s.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ module.exports = {
}

const { io, parsedMessage } = result;

try {
await gem2sResponse(io, parsedMessage);
} catch (e) {
logger.error(
'Pipeline response handler failed with error: ', e,
);

AWSXRay.getSegment().addError(e);
res.status(200).send('nok');
return;
if (parsedMessage) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that if parsedMessage doesn't exist, the function will return 200? Would it be better to throw something which says parsedMessage doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The absence of parsed message does not mean that an error has occurred: parseSNSMessage returns a { io, parsedMessage } if its input has Type == Notification; otherwise (SubscriptionConfirmation or UnsubscribeConfirmation) it returns {}. When it returns {}, it logs an annoying validation error.

That said, my comparison is wrong and should check for parsedMessage != undefined instead of just parsedMessage, just in case we do get something falsy as the parseMessage.

try {
await gem2sResponse(io, parsedMessage);
} catch (e) {
logger.error(
'gem2s pipeline response handler failed with error: ', e,
);

AWSXRay.getSegment().addError(e);
res.status(200).send('nok');
return;
}
}

res.status(200).send('ok');
Expand Down
20 changes: 11 additions & 9 deletions src/api/routes/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ module.exports = {

const { io, parsedMessage } = result;

try {
await pipelineResponse(io, parsedMessage);
} catch (e) {
logger.error(
'Pipeline response handler failed with error: ', e,
);
if (parsedMessage) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern as in routes/gem2s.js

try {
await pipelineResponse(io, parsedMessage);
} catch (e) {
logger.error(
'qc pipeline response handler failed with error: ', e,
);

AWSXRay.getSegment().addError(e);
res.status(200).send('nok');
return;
AWSXRay.getSegment().addError(e);
res.status(200).send('nok');
return;
}
}

res.status(200).send('ok');
Expand Down
4 changes: 3 additions & 1 deletion src/api/routes/plots-tables.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const PlotsTablesService = require('../route-services/plots-tables');
const { NotFoundError } = require('../../utils/responses');


const plotsTablesService = new PlotsTablesService();

Expand All @@ -16,7 +18,7 @@ module.exports = {
.then((response) => res.json(response))
.catch((e) => {
if (e.message.includes('not found')) {
res.status(404).send('');
throw (new NotFoundError('Plot not found'));
} else {
throw e;
}
Expand Down
6 changes: 6 additions & 0 deletions src/specs/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ paths:
application/json:
schema:
$ref: ./models/HTTPError.v1.yaml
'404':
description: Experiment/plot not found.
content:
application/json:
schema:
$ref: ./models/HTTPError.v1.yaml
'200':
description: OK
content:
Expand Down
3 changes: 3 additions & 0 deletions src/utils/hookRunner.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const logger = require('./logging');

class hookRunner {
constructor() {
this.hooks = {};
Expand Down Expand Up @@ -27,6 +29,7 @@ class hookRunner {
// eslint-disable-next-line no-await-in-loop
this.results[taskName].push(await this.hooks[taskName][idx](payload));
}
logger.log(`Completed ${this.results[taskName].length} hooks for pipeline task ${taskName}`);

return this.results;
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/parse-sns-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const parseSNSMessage = async (req) => {
logger.error('Error parsing message:', e);
throw e;
}
} else {
logger.log(`SNS message is of type "${msg.Type}", ignoring it`);
}

return {};
Expand Down