Skip to content

Making it possible to access the details of error responses from the API (see #4)#5

Open
11BelowStudio wants to merge 2 commits into
nelson-mig-l:masterfrom
11BelowStudio:error-info
Open

Making it possible to access the details of error responses from the API (see #4)#5
11BelowStudio wants to merge 2 commits into
nelson-mig-l:masterfrom
11BelowStudio:error-info

Conversation

@11BelowStudio

Copy link
Copy Markdown
Contributor

Here's an implementation for #4.

If a NeoCitiesApiError was built from a BaseResponse instance, that response will now be stored in the NeoCitiesApiError instance, and can be accessed later on. If it was built from a Throwable, that field will just be null.

The existing error message building logic, and the now-redundant public NeoCitiesApiError(final String message) constructor have been retained for sake of consistency.

@nelson-mig-l

nelson-mig-l commented Jan 12, 2026

Copy link
Copy Markdown
Owner

Hi Rachel.
Thanks for pointing this out.
I will probably make the distinction between an:

  • Error - reported by the api, always created from a server response
  • Exception - some unexpected error on client side

Just to avoid having to deal will null checks. I will spend some time on this soon.

…st keeping the unsafe direct method of accessing it available.
@11BelowStudio

Copy link
Copy Markdown
Contributor Author

I've had a cunning plan. The getResponse() method now wraps the BaseResponse in an Optional<BaseResponse>, which should make things a little bit safer.

(The alternatives would probably be to change the ask method to either not wrap any IOException in a NeoCitiesApiError (meaning that all the methods of this library would need to have throws IOException on them), or to wrap the IOException inside a different exception, such as an UncheckedIOException (which you might want to document)).

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.

2 participants