IQSS / IQSS/dataverse

Some API calls throw 500 errors instead of intended codes

Open
#7,719 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Help Wanted: Code Type: Bug
Dominant language
Java
Stars
1.1k
Forks
564
Avg merge
2d 2h
Merged PRs (30d)
29

Description

As discovered in #7588, some of the existing API calls incorrectly throw a WrappedResponse which is then caught by the ThrowableHandler class. It looks like these may have originated from incorrect adaptation of methods that use the AbstractApiBean.response(DataverseRequestHandler) method, e.g. edu.harvard.iq.dataverse.api.Info.getTermsOfUse(), where the response method correctly unwraps the WrappedResponse.

This issue is nominally about finding and fixing the methods that are returning incorrect response codes. They should be findable via a search for API methods that 'throw WrappedResponse' - any top level method (one that corresponds to an endpoint) that does this is either incorrect or doesn't actually throw a WrappedResponse under any circumstance.

After tech hours discussion about the best way to fix these methods, the general consensus was to work to adapt them to avoid using WrappedResponse and instead to have classes that now generate a WrappedResponse to throw the appropriate subclass of javax.ws.rs.WebApplicationException. This leverages a standard Java RESTful services mechanism rather than a Dataverse-specific mechanism. (The expectation is then that new API calls should use WebApplicationExceptions as well. It may also make sense to convert some existing methods: for example, the findUser* methods currently throw a WrappedResponse and if they are changed to send WebApplicationExceptions to fix some of the API calls that are not working now, it might make sense to also change API calls that were using try/catch blocks to unwrap the WrappedResponse (so they were working, but now don't need to have the try/catch).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the API methods for "throw WrappedResponse", then compare top-level endpoints with AbstractApiBean.response(DataverseRequestHandler), using Info.getTermsOfUse() and ThrowableHandler as the initial references. Review the affected methods and the findUser* methods, then verify that affected API calls return their intended response codes through WebApplicationException rather than incorrect 500 responses.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.