Skip to content

Commit a020c2d

Browse files
author
William Tsai
committed
Update readme description
1 parent e368c4d commit a020c2d

1 file changed

Lines changed: 23 additions & 28 deletions

File tree

README.md

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ return success_response(data) if success?
6666
```
6767

6868
```json
69+
// response status: 200
70+
// response body:
6971
{
70-
"status": 200,
71-
"json": {
72-
"data": {
73-
"a": 1,
74-
"b": 2
75-
}
76-
}
72+
"data": {
73+
"a": 1,
74+
"b": 2
75+
}
7776
}
7877
```
7978

@@ -87,37 +86,31 @@ return error_response(:bad_request_1) if failed?
8786
```
8887

8988
```json
89+
// response status: 400
90+
// response body:
9091
{
91-
"status": 400,
92-
"json":
93-
{
94-
"error_code": 400001,
95-
"error_message": "bad request 1",
96-
"error_key": "bad_request_1",
97-
"a": 1,
98-
"b": 2
99-
}
92+
"error_code": 400_001,
93+
"error_message": "bad request 1",
94+
"error_key": "bad_request_1"
10095
}
10196
```
10297

103-
You can also provide your custom error message and error data. If error data is a hash, it will be merged into the json response; if it is an array, it will be merged into the json response with an `error_data` key.
98+
You can also provide your custom error message and error data. If error data is a hash, it will be merged into the json response; If it is an array, it will be merged into the json response with an `error_data` key.
10499

105100
```ruby
106101
# in controller actions
107-
return error_response(:bad_request_1, 'no required data', { a: 1, b: 2}) if failed?
102+
return error_response(:bad_request_1, 'no required data', { a: 1, b: 2 }) if failed?
108103
```
109104

110105
```json
106+
// response status: 400
107+
// response body:
111108
{
112-
"status": 400,
113-
"json":
114-
{
115-
"error_code": 400001,
116-
"error_message": "bad request 1",
117-
"error_key": "bad_request_1",
118-
"a": 1,
119-
"b": 2
120-
}
109+
"error_code": 400_001,
110+
"error_message": "bad request 1: no required data",
111+
"error_key": "bad_request_1",
112+
"a": 1,
113+
"b": 2
121114
}
122115
```
123116

@@ -148,8 +141,10 @@ ErrorResponse.to_hash(:bad_request_1)
148141
gives you
149142

150143
```json
144+
// response status: 400
145+
// response body:
151146
{
152-
"error_code": 400001,
147+
"error_code": 400_001,
153148
"error_message": "bad request 1",
154149
"error_key": "bad_request_1"
155150
}

0 commit comments

Comments
 (0)