feature/Reynolds-and-Reynolds-DMS-API-Integration -Expand
This commit is contained in:
26
server/rr/rr-error.js
Normal file
26
server/rr/rr-error.js
Normal file
@@ -0,0 +1,26 @@
|
||||
class RrApiError extends Error {
|
||||
constructor(message, { reqId, url, apiName, errorData, status, statusText } = {}) {
|
||||
super(message);
|
||||
this.name = "RrApiError";
|
||||
this.reqId = reqId;
|
||||
this.url = url;
|
||||
this.apiName = apiName;
|
||||
this.errorData = errorData;
|
||||
this.status = status;
|
||||
this.statusText = statusText;
|
||||
}
|
||||
}
|
||||
|
||||
// Match Rome/RR envelope once you confirm it; keep this central.
|
||||
function assertRrOk(data, { apiName, allowEmpty = false } = {}) {
|
||||
// Example heuristics — update to exact envelope from the PDF:
|
||||
// - successFlag === true, or
|
||||
// - code === "0", or
|
||||
// - !error / !errors length, etc.
|
||||
if (!allowEmpty && (data == null || data.error || data.errors?.length)) {
|
||||
throw new RrApiError(`${apiName} returned an error`, { errorData: data });
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
module.exports = { RrApiError, assertRrOk };
|
||||
Reference in New Issue
Block a user