Browse Source

return errors correctly to client

Mark deVilliers 2 years ago
parent
commit
8a23ee27be
1 changed files with 22 additions and 18 deletions
  1. 22 18
      node/api/entitlements.go

+ 22 - 18
node/api/entitlements.go

@@ -25,7 +25,7 @@ type EntitlementRequest struct {
25 25
 	AccessLevel AccessLevel `json:"level" description:"access level requested. Valid values 'owner-only', 'can-read','can-discover'" validate:"nonzero"`
26 26
 }
27 27
 
28
-//Entitlement is returned to encapsulate the current status of the entitlement
28
+// Entitlement is returned to encapsulate the current status of the entitlement
29 29
 type Entitlement struct {
30 30
 	EntitlementRequest
31 31
 	UID    string `json:"uid" description:"unique identifier of the entitlement request" validate:"nonzero"`
@@ -324,29 +324,33 @@ func (e entitlementResource) amendAcceptedEntitlement(request *restful.Request,
324 324
 	// if the entitlement is now not discoverable we will need to
325 325
 	// remove the data from the metadata service
326 326
 	if !req.IsDiscoverable() {
327
-		go func() {
328 327
 
329
-			subject, err := utils.ParseSubject(req.Subject)
328
+		subject, err := utils.ParseSubject(req.Subject)
330 329
 
331
-			if err != nil {
332
-				log.Println("error parsing subject : ", subject)
333
-				return
334
-			}
330
+		if err != nil {
331
+			log.Println("error parsing subject : ", subject)
332
+			response.WriteHeaderAndEntity(http.StatusInternalServerError, ErrorResponse{Error: err.Error()})
335 333
 
336
-			metaData, found := e.metaStore.FindBySubject(subject)
334
+			return
335
+		}
337 336
 
338
-			if !found {
339
-				log.Println("error finding metadata for subject : ", subject)
340
-				return
341
-			}
337
+		metaData, found := e.metaStore.FindBySubject(subject)
342 338
 
343
-			_, err = e.mClient.RemoveFromCatalog(metaData.CatalogUID)
339
+		if !found {
340
+			log.Println("error finding metadata for subject : ", subject)
341
+			response.WriteHeaderAndEntity(http.StatusInternalServerError, ErrorResponse{Error: "error finding metadata"})
344 342
 
345
-			if err != nil {
346
-				log.Println("error removing from catalog : ", err.Error())
347
-				return
348
-			}
349
-		}()
343
+			return
344
+		}
345
+
346
+		_, err = e.mClient.RemoveFromCatalog(metaData.CatalogUID)
347
+
348
+		if err != nil {
349
+			log.Println("error removing from catalog : ", err.Error(), subject.String(), metaData)
350
+			response.WriteHeaderAndEntity(http.StatusInternalServerError, ErrorResponse{Error: err.Error()})
351
+
352
+			return
353
+		}
350 354
 	}
351 355
 
352 356
 	response.WriteEntity(req)