Skip to content

Latest commit

 

History

History
77 lines (63 loc) · 1.35 KB

File metadata and controls

77 lines (63 loc) · 1.35 KB

Feign-Custom-Exception-Code-Demo

Introduction

An exception occurred in the system when using the feign, can response the custom structure.

Custom response structure example

{"code": -1, "message": "system error", "data": null}

Environment

  • JDK 1.8

Getting Started

  1. Clone this repository using git clone.
  2. Open the cloned project.
  3. Import the pom.xml file from the root directory using Maven Projects.
  4. Find each Application class to run each module.

Module

  • eureka
  • gateway
  • order-service
  • product-service
  • manager-web

Test Case

  • Case1: Success
POST http://localhost:8081/manager/order/create
Content-Type: application/json

{
  "userId" : 1000,
  "productId" : 1,
  "num" : 1
}
  • Case2: Fail, parameter validate error
POST http://localhost:8081/manager/order/create
Content-Type: application/json

{
  "userId" : null,
  "productId" : 1,
  "num" : 1
}
  • Case3: Fail, product not exist
POST http://localhost:8081/manager/order/create
Content-Type: application/json

{
  "userId" : 1000,
  "productId" : 3,
  "num" : 1
}
  • Case4: Fail, not enough stock
POST http://localhost:8081/manager/order/create
Content-Type: application/json

{
  "userId" : 1000,
  "productId" : 2,
  "num" : 1
}

License

MIT