From 707af8b9199e5643b987896fdab4b937aa35e690 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Wed, 7 Feb 2024 15:32:30 +0100 Subject: [PATCH] Set exception code to be integer --- internal/app/reports/model.go | 2 +- internal/app/reports/service.go | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/app/reports/model.go b/internal/app/reports/model.go index 9ae6af9..805ea14 100644 --- a/internal/app/reports/model.go +++ b/internal/app/reports/model.go @@ -8,7 +8,7 @@ type ReportingPeriod struct { } type Exception struct { - Code string `json:"code"` + Code int `json:"code"` Severity string `json:"severity"` Message string `json:"message"` HelpUrl string `json:"help-url"` diff --git a/internal/app/reports/service.go b/internal/app/reports/service.go index b237970..b2f8dd6 100644 --- a/internal/app/reports/service.go +++ b/internal/app/reports/service.go @@ -83,7 +83,7 @@ func (service *ReportsService) GenerateDatasetUsageReport(repoId string, startDa // This information would need to come from our API which would require a lookup based on dataset-id // This could provide too much of an overhead for report generation. exceptions = append(exceptions, Exception{ - Code: "3071", + Code: 3071, Severity: "warning", Message: "dataset-title", Data: "dataset-title is unavailable in this report, can be obtained from metadata lookup based on dataset-id", @@ -92,14 +92,14 @@ func (service *ReportsService) GenerateDatasetUsageReport(repoId string, startDa // Add missing attribute exceptions for potentially missing data if sharedData.Platform == "" { exceptions = append(exceptions, Exception{ - Code: "3071", + Code: 3071, Severity: "warning", Message: "platform", }) } if sharedData.Publisher == "" { exceptions = append(exceptions, Exception{ - Code: "3071", + Code: 3071, Severity: "warning", Message: "publisher", Data: "publisher is unavailable in this report, can be obtained from metadata lookup based on dataset-id", @@ -107,7 +107,7 @@ func (service *ReportsService) GenerateDatasetUsageReport(repoId string, startDa } if sharedData.PublisherId == "" { exceptions = append(exceptions, Exception{ - Code: "3071", + Code: 3071, Severity: "warning", Message: "publisher-id", Data: "publisher-id is unavailable in this report, can be obtained from metadata lookup based on dataset-id", @@ -117,7 +117,7 @@ func (service *ReportsService) GenerateDatasetUsageReport(repoId string, startDa if addCompressedHeader { // Add exception that this will be compressed report exceptions = append(exceptions, Exception{ - Code: "69", + Code: 69, Message: "Report is compressed using gzip", Severity: "warning", HelpUrl: "https://github.com/datacite/sashimi", @@ -251,13 +251,6 @@ func SendReportToAPI(reportsAPIEndpoint string, compressedJson []byte, jwt strin return err } - // Print response body - buf := new(bytes.Buffer) - buf.ReadFrom(res.Body) - newStr := buf.String() - log.Println(newStr) - - // Check response code switch res.StatusCode { case http.StatusCreated: