Skip to content

Conversation

@sebastianchristopher
Copy link

We can already do this for edit, adding for delete.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for deleting assignments using non-numeric identifiers (such as lti_context_id:ab84f579-4442-4d4a-acd8-85c5ec6fd2b6), mirroring existing functionality that already exists for editing assignments.

Changes:

  • Added a String overload for deleteAssignment() to accept non-numeric assignment IDs alongside the existing Integer version
  • Includes enhanced error handling with CanvasException for detailed error reporting

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/java/edu/ksu/canvas/interfaces/AssignmentWriter.java Adds interface method signature for deleteAssignment with String assignmentId parameter
src/main/java/edu/ksu/canvas/impl/AssignmentImpl.java Implements the new deleteAssignment overload with comprehensive error handling including 200, 204, and 404 status codes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +85 to +107
LOG.debug("response {}", response);
int code = response.getResponseCode();

boolean errorHappened = response.getErrorHappened();

if (!errorHappened) {
switch (code) {
case 200:
return responseParser.parseToObject(Assignment.class, response);
case 204:
case 404: // already deleted, treat as success
return Optional.empty();
default:
// fall through to error
}
}

String msg = response.getContent();
if (msg == null || msg.isBlank()) {
msg = "Canvas returned HTTP " + code;
}

throw new CanvasException(msg, url, response);
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The error handling in this String overload is inconsistent with the Integer overload (lines 66-77). The Integer version simply returns Optional.empty() on any error or non-200 status code, while this version throws CanvasException with detailed error information. This creates API inconsistency where the same logical operation behaves differently based on the parameter type.

Consider either:

  1. Updating the Integer overload to use the same sophisticated error handling, or
  2. Simplifying this implementation to match the Integer overload's behavior

For consistency with other delete operations in the codebase (e.g., CalendarEventImpl line 75-85, AssignmentGroupImpl line 82-87), the simpler error handling pattern (returning Optional.empty() on error) appears to be the established convention.

Suggested change
LOG.debug("response {}", response);
int code = response.getResponseCode();
boolean errorHappened = response.getErrorHappened();
if (!errorHappened) {
switch (code) {
case 200:
return responseParser.parseToObject(Assignment.class, response);
case 204:
case 404: // already deleted, treat as success
return Optional.empty();
default:
// fall through to error
}
}
String msg = response.getContent();
if (msg == null || msg.isBlank()) {
msg = "Canvas returned HTTP " + code;
}
throw new CanvasException(msg, url, response);
LOG.debug("response " + response.toString());
if(response.getErrorHappened() || response.getResponseCode() != 200){
LOG.debug("Failed to delete assignment, error message: " + response.toString());
return Optional.empty();
}
return responseParser.parseToObject(Assignment.class, response);

Copilot uses AI. Check for mistakes.
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 sorta with Copilot here, it seems the new method is quite different to the existing delete method and having different behaviour across 2 very similar methods is confusing.

Choose a reason for hiding this comment

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

True, perhaps it needs a wider rewrite... it seems odd to me that everything other than a 200 just returns an empty optional - it's not very illuminating and leaves the calling code to guess what the problem might be.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
LOG.debug("response {}", response);
int code = response.getResponseCode();

boolean errorHappened = response.getErrorHappened();
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 this is actually used in the production code.

Choose a reason for hiding this comment

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

Don't follow sorry?

Choose a reason for hiding this comment

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

Ah because it's getting intercepted by simple rest client

case 200:
return responseParser.parseToObject(Assignment.class, response);
case 204:
case 404: // already deleted, treat as success
Copy link
Member

Choose a reason for hiding this comment

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

I think this case is already handled in the SimpleRestClient checks so seems a little strange having it here.

Choose a reason for hiding this comment

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

I don't think the 404 will be, but perhaps it's best handled in the calling code

Comment on lines +85 to +107
LOG.debug("response {}", response);
int code = response.getResponseCode();

boolean errorHappened = response.getErrorHappened();

if (!errorHappened) {
switch (code) {
case 200:
return responseParser.parseToObject(Assignment.class, response);
case 204:
case 404: // already deleted, treat as success
return Optional.empty();
default:
// fall through to error
}
}

String msg = response.getContent();
if (msg == null || msg.isBlank()) {
msg = "Canvas returned HTTP " + code;
}

throw new CanvasException(msg, url, response);
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 sorta with Copilot here, it seems the new method is quite different to the existing delete method and having different behaviour across 2 very similar methods is confusing.

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