Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OperationResult class and begin handling sql errors more gracefully #608

Merged
merged 15 commits into from
Jan 25, 2023

Conversation

dmtrek14
Copy link
Collaborator

This PR begins to address #496 by adding an OperationResult class and updates code related to the creation of Projects to begin using this class. Changes in these commits include:

  • Add the OperationResult class
  • Refactor Project DAO and Facade to use this class
  • Update createProjectsService to check class
  • Update projectManagement.js exception handler for project creation to pass along the message from the back end.

Comments and suggestions welcome as my PHP is a bit rusty.

Copy link
Member

@anarute anarute left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks pretty good! I've added some comments but they are all details, on Monday I can run it locally and help testing too.

model/OperationResult.php Outdated Show resolved Hide resolved
model/OperationResult.php Outdated Show resolved Hide resolved
model/facade/action/CreateProjectAction.php Show resolved Hide resolved
web/js/projectManagement.js Outdated Show resolved Hide resolved
web/js/projectManagement.js Outdated Show resolved Hide resolved
'exception': function(proxy, type, action, exception, res){
var parser = new DOMParser();
var errorDoc = parser.parseFromString(res.responseText, "text/xml");
var errorMessage = errorDoc.getElementsByTagName("error")[0].childNodes[0].nodeValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how the format of the XML response is but is it possible to have multiple error elements? In this case we may need to be more specific to be sure we are displaying all the errors, but I'm happy to fetch this and test it next week as well as I'm not completely sure how it works.

Copy link
Collaborator Author

@dmtrek14 dmtrek14 Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to since we control the shape of the xml sent back (in the service). We could either add as many distinct <error> elements to the object as needed or concat multiple errors into one message. Then just parse this out to the alert. I'll test the js here with multiple <error> elements; I probably need to modify the last bit of code since it's taking the first items out of the arrays instead of looping. Good catch on this. I'll do some local testing on multiple messages.

Copy link
Member

@jaragunde jaragunde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this! I always feel sad whenever I get one of those indescriptive error messages. It's also a great way to get a feel of the project, working across all the layers.

model/facade/ProjectsFacade.php Outdated Show resolved Hide resolved
model/facade/ProjectsFacade.php Outdated Show resolved Hide resolved
@jaragunde
Copy link
Member

jaragunde commented Jan 16, 2023

Maybe you already know or have a better way to do it, but there's a web/APITest.php page where you can send any random request to make the endpoint fail in the ways you want. Thanks again for your work :)

@anarute
Copy link
Member

anarute commented Jan 16, 2023

I just noticed that even with an error, the project isn't created in the database but it is shown in the project table, so I think we should also remove it from the front end in case it fails to avoid confusion like people thinking the project was created even with errors when it wasn't.

Btw, this is a behavior that was not caused by your patch, but I think is a good opportunity to fix it too.

- Return array of OperationResults if we are creating multiple projects
- Check for null dates and format appropriately if not null
- Check in service for multiple items saved
- Service handle multiple errors
@dmtrek14
Copy link
Collaborator Author

@anarute That's a good catch. I just added a call to reload the data store if creation fails so that we don't have a bad phantom record listed.

Copy link
Member

@jaragunde jaragunde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I just caught a small mistake, see below. Thanks!

web/services/createProjectsService.php Outdated Show resolved Hide resolved
Copy link
Member

@jaragunde jaragunde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mind drifted back to the review and I added a few more comments... 😇

web/services/createProjectsService.php Show resolved Hide resolved
web/services/createProjectsService.php Outdated Show resolved Hide resolved
web/services/createProjectsService.php Outdated Show resolved Hide resolved
Copy link
Member

@jaragunde jaragunde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I noticed a few more issues, but this is looking great. Thanks a lot!

model/OperationResult.php Outdated Show resolved Hide resolved
web/services/createProjectsService.php Outdated Show resolved Hide resolved
- Use spaces instead of tabs in OperationResult object
- Make props private since we have public getters
- Update service to use getters
- Update DAO to init object with isSuccessful set to false
Copy link
Member

@jaragunde jaragunde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I caught a PHP warning but, other than that, my tests were successful. Thanks!

web/services/createProjectsService.php Outdated Show resolved Hide resolved
@dmtrek14 dmtrek14 marked this pull request as ready for review January 20, 2023 16:11
@dmtrek14 dmtrek14 merged commit a968bd1 into main Jan 25, 2023
@dmtrek14 dmtrek14 deleted the bubble-up-sql-errors branch January 25, 2023 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants