Dear Sir/Madam,

The following program works when there is data in the table. I want to 
capture the situation when the server side code returns no data. 

How do I capture the response status?

Please help.

Regards,
Partha

*Angular Side Code:*

constructor(private httpClient: HttpClient, private router: Router) {}

getRoles() {
this.httpClient
.get<{message: string, roles: Role[], recordGoodCount: number}>(
'http://localhost:3000/api/role')
.subscribe((roleData) => {
alert(roleData.roles.length);
this.roleList = roleData.roles;
this.roleListUpdated.next([...this.roleList]);
});
}



*Server Side Code:*


router.get("", (request, response, next) => {
(async () => {
const SQLStatement = "SELECT PF_ROLE_CODE roleCode, PF_ROLE_NAME roleName 
FROM PT_ROLE WHERE PF_DLTD = 'N';";

returnValue = await executeSQL(SQLStatement);
console.log(returnValue[0]);
rolesFetched = [];
recordCount = 0;
returnValue.forEach(element => {
element.forEach(ele => {
recordCount ++;
rolesFetched.push({
roleCode: ele.ROLECODE,
roleName: ele.ROLENAME,
updateUser: ''
});
})
});
console.log(recordCount);

if(recordCount > 0) {
response.status(200).json({
message: 'Roles fetched successfully',
roles: rolesFetched,
recordGoodCount: recordCount
});
} else {
response.status(404).json({
message: 'Roles fetch failed'
});
}
})();
});

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to