Improve responder messages
This commit is contained in:
parent
bb67c4582d
commit
6041aea8ed
10
src/main.ts
10
src/main.ts
|
@ -26,7 +26,11 @@ http
|
||||||
try {
|
try {
|
||||||
temp = JSON.parse(chunk);
|
temp = JSON.parse(chunk);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(origin + "Chunk is not valid JSON");
|
logger.error("Recieved chunk was not valid JSON!");
|
||||||
|
|
||||||
|
res.writeHead(400, contentType);
|
||||||
|
res.write(response.JsonError("recieved chunk was not valid JSON"));
|
||||||
|
res.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +47,7 @@ http
|
||||||
);
|
);
|
||||||
|
|
||||||
res.writeHead(201, contentType);
|
res.writeHead(201, contentType);
|
||||||
res.write(response.success("Review was sent"));
|
res.write(response.success("review was sent"));
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -58,7 +62,7 @@ http
|
||||||
logger.log(`${sender} cannot ${req.method} to ${req.url}`);
|
logger.log(`${sender} cannot ${req.method} to ${req.url}`);
|
||||||
|
|
||||||
res.writeHead(400, contentType);
|
res.writeHead(400, contentType);
|
||||||
res.write(JSON.stringify({ error: { type: "generic", error: `Cannot ${req.method} to ${req.url}` }}));
|
res.write(response.requestError(`Cannot ${req.method} to ${req.url}`));
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,4 +17,22 @@ export class Responder {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public requestError(errorMessage: string): string {
|
||||||
|
return JSON.stringify({
|
||||||
|
error: {
|
||||||
|
type: "RequestError",
|
||||||
|
message: errorMessage
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonError(errorMessage: string): string {
|
||||||
|
return JSON.stringify({
|
||||||
|
error: {
|
||||||
|
type: "JsonError",
|
||||||
|
message: errorMessage
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue