Skip to content

Commit f0b7b60

Browse files
Docs updated
1 parent b402075 commit f0b7b60

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ all can be done with zero custom code but by specifying error details in `proper
2727

2828
> **Current version: 1.0**
2929
30+
Add the `spring-boot-problem-handler` jar to application dependencies. That is all it takes to get a default working
31+
exception handling mechanism in a Spring boot application.
32+
3033
```xml
3134
<properties>
3235
<spring-boot-problem-handler.version>1.0</spring-boot-problem-handler.version>
3336
</properties>
3437
```
3538

36-
Add the `spring-boot-problem-handler` jar to application dependencies. That is all it takes to get a default working
37-
exception handling mechanism in a Spring boot application.
3839
```xml
3940
<dependency>
4041
<groupId>io.github.officiallysingh</groupId>
@@ -284,7 +285,7 @@ but not recommended.
284285
To be on safer side, it's recommended to keep it `true`, in that case if some message is not found,
285286
the message key is taken as its value, which can be updated later into `properties` file, once noticed.
286287

287-
### Problem Properties
288+
## Problem Properties
288289
**Following are the configurations** to customize default behaviour of `spring-boot-problem-handler`.
289290
```properties
290291
problem.enabled=true
@@ -324,9 +325,8 @@ problem.open-api.res-validation-enabled=false
324325
* `problem.open-api.req-validation-enabled`:- To enable or disable OpenAPI specification validation for request, default is `false`.
325326
* `problem.open-api.res-validation-enabled`:- To enable or disable OpenAPI specification validation for response, default is `false`.
326327

327-
## Usage
328328

329-
### Error Key
329+
## Error Key
330330
The main concept behind specifying the error attributes in `properties` file is **Error key**, which is mandatory to be unique for each error scenario.
331331
**It is either derived or specified by application** while throwing exception and used to externalize the error attributes in `properties` file.
332332

@@ -350,7 +350,7 @@ status.some.error.key=400
350350
* When controller method name changes or controller argument Object class name or any of its property name changes then `jakarta.validation.*` violation error keys may change.
351351
* When database constraint name or index name changes then any `DuplicateKeyException` or `DataIntegrityViolationException` error key may change.
352352

353-
### Error response structure
353+
## Error response
354354
Following is an example response body for an error.
355355
```json
356356
{
@@ -373,8 +373,8 @@ Response Header when service is configured for XML `HttpMessageConverters`
373373
content-type: application/problem+xml
374374
```
375375

376-
**Error Response description**
377-
* `type`:- A URI reference that identifies the problem type. When dereferenced, it provides human-readable documentation for this error.
376+
**Description**
377+
* `type`:- A `URI` reference that identifies the problem type. When dereferenced, it provides human-readable documentation for this error.
378378
If not set `about:blank` is taken as default.
379379
* `title`:- A short, human-readable summary of the error such as `Bad Request`.
380380
* `status`:- The HTTP status code, int value such as `500`.
@@ -386,7 +386,7 @@ content-type: application/problem+xml
386386
Used in `type`. Commonly used to set unique codes for different business error scenarios.
387387

388388

389-
### Problem Message resolvers
389+
## Problem Message resolvers
390390
To know how to define the error attributes in properties file, enable debugging as follows.
391391
```properties
392392
problem.debug-enabled=true
@@ -451,15 +451,15 @@ detail.org.springframework.batch.core.repository.JobInstanceAlreadyCompleteExcep
451451
```
452452

453453
To minimize the number of properties following defaults are taken if `HttpStatus` is specified as `status.`(error key) property.
454-
* Code is taken as specified `HttpStatus`'s int code e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Code default would be `417`
455-
* Title is taken as specified `HttpStatus`'s reason phrase e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Title default would be `Expectation Failed`
456-
* Detail default is taken from thrown exception's `exception.getMessage()`.
454+
* **Code** is taken as specified `HttpStatus`'s int code e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Code default would be `417`
455+
* **Title** is taken as specified `HttpStatus`'s reason phrase e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Title default would be `Expectation Failed`
456+
* **Detail** default is taken from thrown exception's `exception.getMessage()`.
457457

458458
> [!NOTE]
459459
> `status.`(error key) property is considered only for exceptions where no explicit advice is defined,
460460
otherwise `HttpStatus` is specified in the java code.
461461

462-
### Creating and throwing exceptions
462+
## Creating and throwing exceptions
463463

464464
Apart from exceptions thrown by frameworks or java, every application need to throw custom exceptions.
465465
[**`ApplicationProblem`**](src/main/java/com/ksoot/problem/core/ApplicationProblem.java) and
@@ -486,9 +486,9 @@ detail.sample.problem=Some message details
486486
But exceptions come with some default attributes as follows, to minimize the number of properties required to be defined in `properties` file
487487

488488
If the messages are not found in `properties` files, defaults are taken as follows.
489-
* Code is taken as specified `HttpStatus`'s int code e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Code default would be `417`
490-
* Title is taken as specified `HttpStatus`'s reason phrase e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` like the Title default would be `Expectation Failed`
491-
* Detail default is taken as thrown exception's `exception.getMessage()`
489+
* **Code** is taken as specified `HttpStatus`'s int code e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Code default would be `417`
490+
* **Title** is taken as specified `HttpStatus`'s reason phrase e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` like the Title default would be `Expectation Failed`
491+
* **Detail** default is taken as thrown exception's `exception.getMessage()`
492492

493493
There are multiple other methods available while creating and throwing exceptions in [**`Problems`**](src/main/java/com/ksoot/problem/Problems.java),
494494
for details refers to its source code and java docs.
@@ -531,7 +531,7 @@ private static final class MyException extends RuntimeException {
531531
}
532532
```
533533

534-
### Stack traces
534+
## Stack traces
535535
Set following property to `true` to get the `stacktrace` in error response,
536536
should only be used on local for debugging purpose and strictly prohibited elsewhere as it may expose application internals.
537537
```properties
@@ -563,7 +563,7 @@ Example response
563563
}
564564
```
565565

566-
### Cause chains
566+
## Cause chains
567567
An exception may have a cause, which in tern may also have another and so on.
568568
The complete cause chain can also be viewed in error response, again it should just be used for local debugging purposes only.
569569

@@ -697,7 +697,7 @@ class CustomMethodArgumentNotValidExceptionHandler implements MethodArgumentNotV
697697
}
698698
```
699699

700-
### Define new advices
700+
## Define new advices
701701
There should not be any need to create any custom exception hence new advices, but if there is a pressing need to do so,
702702
custom exception can be created and corresponding custom `ControllerAdvice` can be defined for the same, though not recommended.
703703
Following example demonstrates a new advice for some custom exception `MyCustomException`.

0 commit comments

Comments
 (0)