Skip to content

Commit

Permalink
create parsing exception from client
Browse files Browse the repository at this point in the history
  • Loading branch information
Fagorym committed Oct 23, 2023
1 parent 40af59d commit 280fb05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/ru/nsu/fit/directors/userservice/api/OrderApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriBuilder;
import ru.nsu.fit.directors.userservice.dto.response.BaseResponse;
import ru.nsu.fit.directors.userservice.exception.ClientException;
import ru.nsu.fit.directors.userservice.exception.ServerNotAvailableException;

Expand Down Expand Up @@ -43,8 +44,14 @@ public <T> List<T> syncListGetWithParams(Function<UriBuilder, URI> uriBuilder, C
.uri(uriBuilder)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, response -> response.bodyToMono(String.class).map(ClientException::new))
.onStatus(HttpStatusCode::is5xxServerError, response -> response.bodyToMono(String.class).map(ServerNotAvailableException::new))
.onStatus(
HttpStatusCode::is4xxClientError,
response -> response.bodyToMono(BaseResponse.class).map(resp -> new ClientException(resp.getException().getMessage()))
)
.onStatus(
HttpStatusCode::is5xxServerError,
response -> response.bodyToMono(String.class).map(ServerNotAvailableException::new)
)
.toEntityList(type)
.block())
.map(ResponseEntity::getBody)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.nsu.fit.directors.userservice.dto.response;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
Expand All @@ -14,6 +15,7 @@
*/
@Getter
@Setter
@NoArgsConstructor
public class BaseResponse<T> {
private T result;
private ResponseException exception;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.nsu.fit.directors.userservice.dto.response;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
Expand All @@ -9,6 +10,7 @@
*/
@Getter
@Setter
@NoArgsConstructor
public class ResponseException {
private String message;
private String type;
Expand Down

0 comments on commit 280fb05

Please sign in to comment.