From b69cc6ce77f99511e42cb29178a10541d5a1fc75 Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Mon, 3 Dec 2018 11:05:14 +0000 Subject: [PATCH] Merge pull request #1211 from sharelatex/ta-fetch-v1-data-log-errors Log Errors in fetchV1Data GitOrigin-RevId: 4b709430c2ad97ca369e93eaa4c4edf5ad7f3f52 --- services/web/app/coffee/models/Institution.coffee | 6 +++++- services/web/app/coffee/models/Publisher.coffee | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/web/app/coffee/models/Institution.coffee b/services/web/app/coffee/models/Institution.coffee index 1cc1cc2fc3..3295b72b57 100644 --- a/services/web/app/coffee/models/Institution.coffee +++ b/services/web/app/coffee/models/Institution.coffee @@ -2,6 +2,7 @@ mongoose = require 'mongoose' Schema = mongoose.Schema ObjectId = Schema.ObjectId settings = require 'settings-sharelatex' +logger = require 'logger-sharelatex' request = require 'request' InstitutionSchema = new Schema @@ -12,7 +13,10 @@ InstitutionSchema = new Schema InstitutionSchema.method 'fetchV1Data', (callback = (error, institution)->) -> url = "#{settings.apis.v1.url}/universities/list/#{this.v1Id}" request.get url, (error, response, body) => - try parsedBody = JSON.parse(body) catch e + try + parsedBody = JSON.parse(body) + catch error # log error and carry on without v1 data + logger.err { model: 'Institution', v1Id: this.v1Id, error }, '[fetchV1DataError]' this.name = parsedBody?.name this.countryCode = parsedBody?.country_code this.departments = parsedBody?.departments diff --git a/services/web/app/coffee/models/Publisher.coffee b/services/web/app/coffee/models/Publisher.coffee index 3426b168ed..e4496b0d42 100644 --- a/services/web/app/coffee/models/Publisher.coffee +++ b/services/web/app/coffee/models/Publisher.coffee @@ -2,6 +2,7 @@ mongoose = require 'mongoose' Schema = mongoose.Schema ObjectId = Schema.ObjectId settings = require 'settings-sharelatex' +logger = require 'logger-sharelatex' request = require 'request' PublisherSchema = new Schema @@ -19,7 +20,10 @@ PublisherSchema.method 'fetchV1Data', (callback = (error, publisher)->) -> pass: settings.apis.v1.pass sendImmediately: true }, (error, response, body) => - try parsedBody = JSON.parse(body) catch e + try + parsedBody = JSON.parse(body) + catch error # log error and carry on without v1 data + logger.err { model: 'Publisher', slug: this.slug, error }, '[fetchV1DataError]' this.name = parsedBody?.name this.partner = parsedBody?.partner callback(null, this)