Commit c045d87f authored by Larbi Gharib's avatar Larbi Gharib
Browse files

Json content type log errors

Change-Id: I1cab969e09dc23b848af9f045874d2b829a9f1b1
parent d63ee362
......@@ -130,14 +130,15 @@ class Auth {
}
cb()
}).catch((error) => {
console.log("Error during API request on checkServerIsInstalled: " + error);
if (error.response.status === 401) {
this.authenticated = false;
}
});
}
checkLastKnownStep(cb) {
if(this.installed){
this.authenticated = true
console.log("Auth: Server is already installed")
cb()
}else{
axios(configApiCall(api_path_get_install_lastKnownStep, 'GET', null, null)).then((response) => {
......@@ -147,10 +148,6 @@ class Auth {
}).catch((error) => {
if(error.response.status === 401){
this.authenticated = false;
console.log("Error during API request on checkLastKnowStep not authenticated!");
}
else{
console.log("Error during API request on checkLastKnowStep: " + error);
}
cb()
})
......@@ -169,7 +166,6 @@ class Auth {
this.authenticated = true
cb()
}).catch((error) => {
console.log("Error during API request on checkLastKnownStep: " + error);
cb()
})
}
......@@ -188,7 +184,6 @@ class Auth {
this.authenticated = true
cb()
}).catch((error) => {
console.log("Error during API request on checkLastKnownStep: " + error);
cb()
})
}
......
import React, {useEffect} from "react";
import { useHistory } from "react-router-dom";
import classnames from "classnames";
import {Formik, Field} from "formik";
// @material-ui/core components
......@@ -38,31 +40,48 @@ const useStyles = makeStyles(styles);
export default function Devices(props) {
const classes = useStyles();
const history = useHistory();
const [devices, setDevices] = React.useState([])
const [selectedDevice, setSelectedDevice]= React.useState({});
const [displayName, setDisplayName] = React.useState("")
const [openEdit, setOpenEdit] = React.useState(false);
const [openRevoke, setOpenRevoke] = React.useState(false);
const userData = {
"username":props.username
"username": props.username
};
useEffect(() => {
auth.checkDirectoryType(() => {
if(auth.hasAdminScope()){
axios(configApiCall(api_path_get_admin_devices, 'GET', userData, null)).then((response)=>{
var resultSet = JSON.parse(response.data.replace(/\s+/g, ' ').trim());
setDevices(resultSet)
if(response.data.length == 0) {
setDevices([]);
}else{
var resultSet = JSON.parse(response.data.replace(/\s+/g, ' ').trim());
setDevices(resultSet)
}
}).catch((error) =>{
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/signin");
}
});
}
else{
axios(configApiCall(api_path_get_auth_devices, 'GET', null, null)).then((response)=>{
var resultSet = JSON.parse(response.data.replace(/\s+/g, ' ').trim());
setDevices(resultSet)
if(response.data.length == 0) {
setDevices([]);
}else{
var resultSet = JSON.parse(response.data.replace(/\s+/g, ' ').trim());
setDevices(resultSet)
}
}).catch((error) =>{
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/signin");
}
});
}
})
......
......@@ -174,7 +174,6 @@ export default function EditBlueprintPermissions(props) {
setUsers(profiles);
})
.catch((error) => {
console.log(error);
setUsers([]);
if (error.response.status === 401) {
auth.authenticated = false;
......
......@@ -127,7 +127,6 @@ export default function Blueprints() {
})
.catch((error) => {
setBlueprints([]);
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
......@@ -159,7 +158,6 @@ export default function Blueprints() {
setBlueprintNameExits(true);
})
.catch((error) => {
console.log(error);
setDisableCreate(false);
setBlueprintNameExits(false);
});
......
......@@ -117,11 +117,10 @@ export default function Users(props) {
setUsers(profiles);
})
.catch((error) => {
console.log(error);
setUsers([]);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}else if(error.response.status === 403){
setAllowedToAdd(false);
}
......@@ -174,7 +173,6 @@ export default function Users(props) {
setLoading(false);
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
......@@ -217,10 +215,9 @@ export default function Users(props) {
setLoading(false);
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
});
}
......
......@@ -158,10 +158,9 @@ export default function EditGroup(props) {
});
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
if (error.response.status === 500) {
setBlueprints([]);
......@@ -185,8 +184,10 @@ export default function EditGroup(props) {
if (error.response.status === 404) {
setGroupMembers([]);
}
else
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/signin");
}
})
......@@ -255,11 +256,10 @@ export default function EditGroup(props) {
setUsers(profiles);
})
.catch((error) => {
console.log(error);
setUsers([]);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
});
};
......@@ -336,7 +336,6 @@ export default function EditGroup(props) {
});
})
.catch((error) => {
console.log(error);
setGroupNameExits(false);
});
};
......
......@@ -165,10 +165,9 @@ export default function Groups() {
setSelectedBlueprint(getBlueprintsOptions()[0]);
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
if (error.response.status === 500) {
setBlueprints([]);
......@@ -212,10 +211,9 @@ export default function Groups() {
setLoading(false);
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
if (error.response.status === 404){
getBlueprints();
......@@ -249,7 +247,6 @@ export default function Groups() {
});
})
.catch((error) => {
console.log(error);
setDisableCreate(false);
setGroupNameExits(false);
});
......
......@@ -243,7 +243,6 @@ export default function DisplayUserProfile(props) {
history.push("/");
}else {
setGroups([]);
console.log(error.response);
}
} else {
setGroups([]);
......@@ -344,10 +343,9 @@ export default function DisplayUserProfile(props) {
});
setGroupMemberships(userGroupsData);
}).catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
if (error.response.status === 404) {
setGroupMemberships([]);
......@@ -357,11 +355,17 @@ export default function DisplayUserProfile(props) {
setLoading(false);
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/signin");
}
});
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/signin");
}
});
} else {
axios(
......@@ -400,10 +404,9 @@ export default function DisplayUserProfile(props) {
});
setGroupMemberships(userGroupsData);
}).catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
if (error.response.status === 404) {
setGroupMemberships([]);
......@@ -412,11 +415,17 @@ export default function DisplayUserProfile(props) {
setLoading(false);
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/signin");
}
});
})
.catch((error) => {
console.log(error);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/signin");
}
});
}
});
......
......@@ -119,7 +119,7 @@ export default function Users(props) {
setLoading(false);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
});
return () => {
......@@ -155,7 +155,7 @@ export default function Users(props) {
setLoading(false);
if (error.response.status === 401) {
auth.authenticated = false;
history.push("/");
history.push("/signin");
}
});
};
......
......@@ -95,6 +95,7 @@ public class LoginServlet extends HttpServlet {
}
}
}
resp.setContentType("application/json;charset=UTF-8");
if (res == null)
TomcatCustomErrorHandler.sendCustomError(resp, 401, "Invalid credentials provided!");
else
......
......@@ -63,6 +63,7 @@ public class AddressServlet extends HttpServlet {
JSONObject obj = new JSONObject();
obj.put("name", username);
resp.setContentType("application/json;charset=UTF-8");
if (username == null) TomcatCustomErrorHandler.sendCustomError(resp,404,"Address not found!");
else resp.getWriter().write(obj.toString());
}
......
......@@ -58,6 +58,7 @@ public class NameServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
NameLookupResponse nameLookupResponse = nameServer.getAddressFromName(req.getPathInfo().replace("/",""));
resp.setContentType("application/json;charset=UTF-8");
if(nameLookupResponse == null) TomcatCustomErrorHandler.sendCustomError(resp,404,"name not found");
else resp.getOutputStream().write(JsonStream.serialize(nameLookupResponse).getBytes());
}
......
......@@ -51,6 +51,7 @@ public class ApiFilter implements Filter {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setContentType("application/json;charset=UTF-8");
if (!Server.isInstalled.get()) {
TomcatCustomErrorHandler.sendCustomError(response,404,"Setup has not yet been completed!");
} else {
......
......@@ -46,6 +46,7 @@ public class InstallFilter implements Filter {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setContentType("application/json;charset=UTF-8");
if(Server.isInstalled.get()){
TomcatCustomErrorHandler.sendCustomError(response,404,"The server is already installed");
}
......
......@@ -41,6 +41,7 @@ public class ServerStatusServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
HashMap<String,String> statusInfo = new HashMap<>();
statusInfo.put("installed",String.valueOf(Server.isInstalled.get()));
resp.setContentType("application/json;charset=UTF-8");
resp.getOutputStream().write(JsonStream.serialize(statusInfo).getBytes());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment