Repository: dmwm/wmcore
Issue: MSPileup: incomplete error message in the response; getPileup fetches all the docs

**Impact of the bug**
MSPileup

**Describe the bug**
Apologies for filing two different issues in the same GH issue, feel free to provide different commits fixing each of them.
 
Based on MSPileup 2.2.0rc1 - running in testbed - I could spot two basic functionality issues:
1) upon providing an ill pileup data structure through a POST request, the service provides a basic and standard error message [1]
2) after injecting pileup objects into the system, if you want to retrieve one of them, the service returns everything from the database [2]

**How to reproduce it**
See instructions in the extra comments

**Expected behavior**
For the validation issue, we should provide what in the document schema is wrong. In other words, which attribute fail to pass the validation, and if possible, we should also provide what that was expected to be.

For the GET call, the service should of course only return the pileup configuration for the requested pileup name.

**Additional context and error message**
[1]
```
cmst1@vocms0193:/data/srv/wmagent/current $ scurl -v -X POST -H "Content-type: application/json" -d '{"pileupName":"/Test/Test-Alan-v1/PREMIX", "pileupType": "wrong", "active": false, "expectedRSEs": ["T2_CH_CERN"]}' https://cmsweb-testbed.cern.ch:8443/ms-pileup/data/pileup
...
        <h2>400 Bad Request</h2>
        <p>MSPileupError: schema error, code: 7</p>
        <pre id="traceback"></pre>
```

[2]
```
cmst1@vocms0193:/data/srv/wmagent/current $ scurl -v -X GET -H "Content-type: application/json" -d '{"pileupName":"/Test/Test-Alan-v2/GEN-SIM"}' https://cmsweb-testbed.cern.ch:8443/ms-pileup/data/pileup
...
{"result": [
 {
  "pileupName": "/sdkjfhsdkf/klsjdflksdj/PREMIX",
...
  "pileupName": "/hasan-test-Neutrino_E-10_gun/Run3Summer21PrePremix-120X_mcRun3_2021_realistic_v6-v2/PREMIX",
...
  "pileupName": "/Test/Test-Alan-v1/PREMIX",
...
  "pileupName": "/Test/Test-Alan-v2/GEN-SIM",
```

Changed files:
src/python/WMCore/MicroService/MSPileup/MSPileupError.py, test/python/WMCore_t/MicroService_t/MSPileup_t/MSPileupData_t.py

diff --git a/src/python/WMCore/MicroService/MSPileup/MSPileupError.py b/src/python/WMCore/MicroService/MSPileup/MSPileupError.py
index 4c1ee76db..22a4217a9 100644
--- a/src/python/WMCore/MicroService/MSPileup/MSPileupError.py
+++ b/src/python/WMCore/MicroService/MSPileup/MSPileupError.py
@@ -74,7 +74,8 @@ class MSPileupGenericError(MSPileupError):
     """
     def __init__(self, data, msg=""):
         super().__init__(data, msg)
-        self.assign(msg="generic error", code=MSPILEUP_GENERIC_ERROR)
+        msg = self.msg if self.msg else "generic error"
+        self.assign(msg=msg, code=MSPILEUP_GENERIC_ERROR)
 
 
 class MSPileupSchemaError(MSPileupError):
@@ -83,7 +84,8 @@ class MSPileupSchemaError(MSPileupError):
     """
     def __init__(self, data, msg=""):
         super().__init__(data, msg)
-        self.assign(msg="schema error", code=MSPILEUP_SCHEMA_ERROR)
+        msg = self.msg if self.msg else "schema error"
+        self.assign(msg=msg, code=MSPILEUP_SCHEMA_ERROR)
 
 
 class MSPileupInvalidDataError(MSPileupError):
@@ -92,7 +94,8 @@ class MSPileupInvalidDataError(MSPileupError):
     """
     def __init__(self, data, msg=""):
         super().__init__(data, msg)
-        self.assign(msg="invalid data", code=MSPILEUP_INVALID_ERROR)
+        msg = self.msg if self.msg else "invalid data"
+        self.assign(msg=msg, code=MSPILEUP_INVALID_ERROR)
 
 
 class MSPileupDuplicateDocumentError(MSPileupError):
diff --git a/test/python/WMCore_t/MicroService_t/MSPileup_t/MSPileupData_t.py b/test/python/WMCore_t/MicroService_t/MSPileup_t/MSPileupData_t.py
index c9d33b7b7..7a9c6c30e 100644
--- a/test/python/WMCore_t/MicroService_t/MSPileup_t/MSPileupData_t.py
+++ b/test/python/WMCore_t/MicroService_t/MSPileup_t/MSPileupData_t.py
@@ -108,7 +108,8 @@ class MSPileupTest(unittest.TestCase):
         out = self.mgr.createPileup(pdict, ['rse2'])[0]
         self.assertEqual(out['error'], "MSPileupError")
         self.assertEqual(out['code'], 7)
-        self.assertEqual(out['message'], "schema error")
+        expect = "Failed to create MSPileupObj, MSPileup input is invalid, expectedRSEs value ['rse1'] is not in validRSEs ['rse2']"
+        self.assertEqual(out['message'], expect)
 
         spec = {'pileupName': pname}
         results = self.mgr.getPileup(spec)