Skip to content

Commit

Permalink
Merge pull request #128 from spaceflightnewsapi/development
Browse files Browse the repository at this point in the history
Small bugfixes found with Sentry
  • Loading branch information
derkweijers authored Mar 20, 2021
2 parents 13d9a90 + edb2888 commit 3d5952d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .strapi-updater.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"latest": "3.5.3",
"lastUpdateCheck": 1615975087162,
"lastUpdateCheck": 1616163288887,
"lastNotification": 1614696645465
}
35 changes: 3 additions & 32 deletions api/article/controllers/article.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
const NodeCache = require("node-cache");
const ObjectID = require("mongodb").ObjectID

const cache = new NodeCache({
stdTTL: 1800,
Expand All @@ -11,36 +12,6 @@ const cache = new NodeCache({
*/

module.exports = {
/**
* Create a record.
*
* @return {Object}
*/

async create(ctx) {
let entity;
try {
entity = await strapi.services.article.create(ctx.request.body);
} catch (e) {
// Update an existing one with update values. Only if from the same news site.
const dup = await strapi.services.article.findOne(e.keyValue);
if (ctx.request.body.newsSite === String(dup.newsSite._id)) {
try {
entity = await strapi.services.article.update(
{ _id: dup._id },
ctx.request.body
);
} catch (e) {
console.error(e);
}
} else {
ctx.throw(409);
}
}
ctx.response.status = 201;
return entity;
},

/**
* Retrieve a record.
*
Expand All @@ -50,8 +21,8 @@ module.exports = {
async findOne(ctx) {
const { id } = ctx.params;

if (id === "launch") {
ctx.throw(404);
if (id === "launch" || !ObjectID.isValid(id)) {
ctx.throw(400);
}

let entity = await strapi.services.article.findOne({ id });
Expand Down
12 changes: 10 additions & 2 deletions api/eventsync/services/eventsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ module.exports = {
}, {upsert: true});
})
} catch (e) {
console.error(`getting upcoming events failed with status: ${e.response.status}`)
if (e.response) {
console.error(`getting upcoming events failed with status: ${e.response.status}`)
} else {
console.error(e)
}
}


Expand All @@ -39,7 +43,11 @@ module.exports = {
}, {upsert: true});
})
} catch (e) {
console.error(`getting previous events failed with status: ${e.response.status}`)
if (e.response) {
console.error(`getting previous events failed with status: ${e.response.status}`)
} else {
console.error(e)
}
}
}
};
12 changes: 10 additions & 2 deletions api/launchsync/services/launchsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ module.exports = {
}
}
} catch (e) {
console.error(`getting upcoming launches failed with status: ${e.response.status}`)
if (e.response) {
console.error(`getting upcoming launches failed with status: ${e.response.status}`)
} else {
console.error(e)
}
}

console.log("getting previous launches")
Expand All @@ -47,7 +51,11 @@ module.exports = {
}
}
} catch (e) {
console.error(`getting previous launches failed with status: ${e.response.status}`)
if (e.response) {
console.error(`getting previous launches failed with status: ${e.response.status}`)
} else {
console.error(e)
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snapi-backend",
"private": true,
"version": "2.3.0",
"version": "2.3.1",
"description": "The backend server for the Spaceflight News API",
"scripts": {
"develop": "strapi develop",
Expand Down

0 comments on commit 3d5952d

Please sign in to comment.