Skip to content

Instantly share code, notes, and snippets.

@max-arshinov
Last active December 10, 2021 08:48
Show Gist options
  • Save max-arshinov/78561fd73e59a9d17ec7563f55de6b40 to your computer and use it in GitHub Desktop.
Save max-arshinov/78561fd73e59a9d17ec7563f55de6b40 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="script.js"></script>
<div id="text1"></div>
<div id="text2"></div>
</body>
</html>
let Failure = class {
constructor(message){
this.message = message;
}
}
let Exception = class {
constructor(message){
this.message = message;
}
}
function getErrorResponse(e){
console.log(e)
if(e instanceof Failure){
// тут еще разное логирование
return {
message: e.message,
errorCode: 422 // в grapqhl будет другой
};
}else{
// тут еще разное логирование
return {
message: 'Ой, что-то пошло не так, наши доблестные инженеры уже все чинят',
errorCode: 500 // в grapqhl будет другой
};
}
}
var response1 = '';
var response2 = '';
try {
throw new Failure('User friendly message here');
}catch(e){
response1 = getErrorResponse(e);
}
console.log(response1)
try {
throw new Exception('User friendly message here');
}catch(e){
response2 = getErrorResponse(e);
}
console.log(response2);
/* todo: add styles */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment