Permalink
Browse files

fix(dao): handle single-entry array responses

  • Loading branch information...
RangerRick committed Jul 21, 2017
1 parent 70fd445 commit 6c66be644edc2db36d4468bb382af2004b507c9b
Showing with 30 additions and 6 deletions.
  1. +5 −1 src/dao/AlarmDAO.ts
  2. +5 −1 src/dao/EventDAO.ts
  3. +20 −4 src/dao/NodeDAO.ts
View
@@ -144,7 +144,11 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
}
if (!Array.isArray(data)) {
throw new OnmsError('Expected an array of alarms but got "' + (typeof data) + '" instead.');
if (data.nodeId) {
data = [data];
} else {
throw new OnmsError('Expected an array of alarms but got "' + (typeof data) + '" instead.');
}
}
return data.map((alarmData) => {
return this.fromData(alarmData);
View
@@ -98,7 +98,11 @@ export class EventDAO extends AbstractDAO<number, OnmsEvent> {
}
if (!Array.isArray(data)) {
throw new OnmsError('Expected an array of events but got "' + (typeof data) + '" instead.');
if (data.nodeId) {
data = [data];
} else {
throw new OnmsError('Expected an array of events but got "' + (typeof data) + '" instead.');
}
}
return data.map((eventData) => {
return this.fromData(eventData);
View
@@ -186,7 +186,11 @@ export class NodeDAO extends AbstractDAO<number, OnmsNode> {
}
if (!Array.isArray(data)) {
throw new OnmsError('Expected an array of nodes but got "' + (typeof data) + '" instead.');
if (data.id) {
data = [data];
} else {
throw new OnmsError('Expected an array of nodes but got "' + (typeof data) + '" instead.');
}
}
return data.map((nodeData) => {
return this.fromData(nodeData);
@@ -237,7 +241,11 @@ export class NodeDAO extends AbstractDAO<number, OnmsNode> {
}
if (!Array.isArray(data)) {
throw new OnmsError('Expected an array of IP interfaces but got "' + (typeof data) + '" instead.');
if (data.nodeId) {
data = [data];
} else {
throw new OnmsError('Expected an array of IP interfaces but got "' + (typeof data) + '" instead.');
}
}
return data.map((ifaceData) => {
return this.fromIpInterfaceData(ifaceData);
@@ -261,7 +269,11 @@ export class NodeDAO extends AbstractDAO<number, OnmsNode> {
}
if (!Array.isArray(data)) {
throw new OnmsError('Expected an array of SNMP interfaces but got "' + (typeof data) + '" instead.');
if (data.ifName) {
data = [data];
} else {
throw new OnmsError('Expected an array of SNMP interfaces but got "' + (typeof data) + '" instead.');
}
}
return data.map((ifaceData) => {
return this.fromSnmpData(ifaceData);
@@ -293,7 +305,11 @@ export class NodeDAO extends AbstractDAO<number, OnmsNode> {
}
if (!Array.isArray(data)) {
throw new OnmsError('Expected an array of services but got "' + (typeof data) + '" instead.');
if (data.lastGood) {
data = [data];
} else {
throw new OnmsError('Expected an array of services but got "' + (typeof data) + '" instead.');
}
}
return data.map((ifaceData) => {
return this.fromServiceData(ifaceData);

0 comments on commit 6c66be6

Please sign in to comment.