-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deploy): display readable error message in log
Closes #1426
- Loading branch information
Showing
5 changed files
with
149 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
client/src/plugins/deployment-tool/errors/ConnectionError.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
export const ConnectionErrorMessages = { | ||
noInternetConnection: 'Could not establish a network connection. Most likely your machine is not online right now.', | ||
unableToConnect: 'Could not connect to the server. Did you run the engine?', | ||
unauthorized: 'Authentication failed. Please check your credentials.', | ||
forbidden: 'This user is not permitted to deploy. Please use different credentials or get this user enabled to deploy.', | ||
notFound: 'Could not find the Camunda endpoint. Please check the URL and make sure Camunda is running.', | ||
internalServerError: 'Camunda is reporting an error. Please check the server status.', | ||
unreachable: 'Camunda is reporting an error. Please check the server status.' | ||
}; | ||
|
||
|
||
export default class ConnectionError extends Error { | ||
constructor(response) { | ||
super(); | ||
|
||
this.message = ( | ||
this.getStatusCodeErrorMessage(response) || | ||
this.getNetworkErrorMessage(response) | ||
); | ||
} | ||
|
||
getStatusCodeErrorMessage(response) { | ||
switch (response.status) { | ||
case 401: | ||
return ConnectionErrorMessages.unauthorized; | ||
case 403: | ||
return ConnectionErrorMessages.forbidden; | ||
case 404: | ||
return ConnectionErrorMessages.notFound; | ||
case 500: | ||
return ConnectionErrorMessages.internalServerError; | ||
case 503: | ||
return ConnectionErrorMessages.unavailable; | ||
} | ||
} | ||
|
||
getNetworkErrorMessage(response) { | ||
if (!/^https?:\/\/localhost/.test(response.url) && !window.navigator.onLine) { | ||
return ConnectionErrorMessages.noInternetConnection; | ||
} | ||
|
||
return ConnectionErrorMessages.unableToConnect; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
client/src/plugins/deployment-tool/errors/DeploymentError.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
const DeploymentErrorMessages = { | ||
noInternetConnection: 'Could not establish a network connection. Most likely your machine is not online right now.', | ||
unableToConnect: 'Could not connect to the server. Did you run the engine?', | ||
bpmnParsingError: 'Server could not parse the diagram. Please check log for errors.', | ||
unauthorized: 'The deployment was unauthorized. Please use valid credentials.', | ||
forbidden: 'The deployment was not permitted for your credentials. Please check your credentials.', | ||
notFound: 'Could not connect to Camunda. Please check the endpoint URL.', | ||
internalServerError: 'Camunda reported an unknown error. Please check the server status.', | ||
serverUnavailable: 'Camunda is currently unavailable. Please try again later.' | ||
}; | ||
|
||
const PARSE_ERROR = 'ENGINE-09005 Could not parse BPMN process. Errors:'; | ||
|
||
|
||
export default class DeploymentError extends Error { | ||
constructor(response, body) { | ||
super(); | ||
|
||
this.message = ( | ||
this.getCamundaBpmErrorMessage(body) || | ||
this.getStatusCodeErrorMessage(response) | ||
); | ||
|
||
this.problems = this.getProblems(body); | ||
} | ||
|
||
getCamundaBpmErrorMessage(body) { | ||
if (body && body.message && body.message.startsWith(PARSE_ERROR)) { | ||
return DeploymentErrorMessages.bpmnParsingError; | ||
} | ||
} | ||
|
||
getStatusCodeErrorMessage(response) { | ||
switch (response.status) { | ||
case 401: | ||
return DeploymentErrorMessages.unauthorized; | ||
case 403: | ||
return DeploymentErrorMessages.forbidden; | ||
case 404: | ||
return DeploymentErrorMessages.notFound; | ||
case 500: | ||
return DeploymentErrorMessages.internalServerError; | ||
case 503: | ||
return DeploymentErrorMessages.serverUnavailable; | ||
} | ||
} | ||
|
||
getNetworkErrorMessage(response) { | ||
if (!/^https?:\/\/localhost/.test(response.url) && !window.navigator.onLine) { | ||
return DeploymentErrorMessages.noInternetConnection; | ||
} | ||
|
||
return DeploymentErrorMessages.unableToConnect; | ||
} | ||
|
||
getProblems(body) { | ||
return body.message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
import ConnectionError from './ConnectionError'; | ||
import DeploymentError from './DeploymentError'; | ||
|
||
export { | ||
ConnectionError, | ||
DeploymentError | ||
}; |