Skip to content

Commit 893efc1

Browse files
committed
feat(Ob2hUM8m): handle timeouts and server unavailable
1 parent d4c8528 commit 893efc1

File tree

27 files changed

+2684
-3
lines changed

27 files changed

+2684
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"DataStoreExample\\": "src/DataStoreExample/src/",
5151
"Task\\": "src/Task/src/",
5252
"HelloUser\\": "src/HelloUser/src/",
53-
"Test\\": "src/Test/src"
53+
"Test\\": "src/Test/src",
54+
"ClientTest\\": "src/ClientTest/src"
5455
}
5556
},
5657
"autoload-dev": {

docs/client.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,31 @@ return [
121121
]
122122
]
123123
];
124+
```
125+
126+
## Обробка помилкових відповідей
127+
128+
В більшості випадків ми очікуємо, що сервер поверне коректну відповідь з коректним описом помилки, як це описано в
129+
маніфесті, але деякі види помилок клієнт генерує на своїй стороні.
130+
131+
Є зарезервовані типи помилок, які клієнт може повернути, але вони не обов'язково повинні бути описані в маніфесті:
132+
- *INVALID_RESPONSE* - якщо ми не можемо розібрати тіло відповіді. Наприклад воно неправильного формату, або містить
133+
синтаксичні помилки.
134+
- *REQUEST_TIMEOUT* - якщо ми отримали 504 чи 524 відповідь від сервера, або взагалі не отримали відповідь по закінченню
135+
таймаута.
136+
- *SERVICE_UNAVAILABLE* - якщо ми отримали 503 відповідь від сервера.
137+
138+
Клієнт повертає помилки як звичайну відповідь, у вигляді наступного шаблону (де type і text можуть змінюватись в
139+
залежності від типу помилки):
140+
```php
141+
[
142+
'data' => null,
143+
'messages' => [
144+
[
145+
'level' => 'error',
146+
'type' => 'INVALID_RESPONSE',
147+
'text' => 'Response body decoding error: "Cannot decode json string: Syntax error."'
148+
]
149+
]
150+
]
124151
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>ClientTest</title>
6+
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/swagger-ui.css" >
7+
<link rel="icon" type="image/png" href="https://unpkg.com/[email protected]/favicon-32x32.png" sizes="32x32" />
8+
<link rel="icon" type="image/png" href="https://unpkg.com/[email protected]/favicon-16x16.png" sizes="16x16" />
9+
<style>
10+
html
11+
{
12+
box-sizing: border-box;
13+
overflow: -moz-scrollbars-vertical;
14+
overflow-y: scroll;
15+
}
16+
17+
*,
18+
*:before,
19+
*:after
20+
{
21+
box-sizing: inherit;
22+
}
23+
24+
body
25+
{
26+
margin:0;
27+
background: #fafafa;
28+
}
29+
.wrapper span.float-right{
30+
display: none;
31+
}
32+
</style>
33+
</head>
34+
35+
<body>
36+
<div id="swagger-ui"></div>
37+
<script src="https://unpkg.com/[email protected]/swagger-ui-standalone-preset.js"></script>
38+
<script src="https://unpkg.com/[email protected]/swagger-ui-bundle.js"></script>
39+
<script>
40+
window.onload = function() {
41+
// Begin Swagger UI call region
42+
const ui = SwaggerUIBundle({
43+
url: 'openapi.yaml',
44+
dom_id: '#swagger-ui',
45+
deepLinking: true,
46+
presets: [
47+
SwaggerUIBundle.presets.apis,
48+
SwaggerUIStandalonePreset
49+
],
50+
plugins: [
51+
SwaggerUIBundle.plugins.DownloadUrl
52+
],
53+
layout: "StandaloneLayout"
54+
})
55+
// End Swagger UI call region
56+
57+
window.ui = ui
58+
}
59+
</script>
60+
</body>
61+
</html>
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
openapi: 3.0.0
2+
info:
3+
version: "1"
4+
title: "ClientTest"
5+
description: Simple manifest for tests
6+
servers:
7+
- url: http://rollun-openapi/openapi/ClientTest/v1
8+
tags:
9+
- name: Resource
10+
paths:
11+
"/resource":
12+
post:
13+
tags:
14+
- Resource
15+
summary: "Make an resource"
16+
description: ""
17+
requestBody:
18+
description: ""
19+
required: true
20+
content:
21+
application/json:
22+
schema:
23+
$ref: '#/components/schemas/ResourcePostRequest'
24+
responses:
25+
"200":
26+
description: "Order successfully created"
27+
content:
28+
application/json:
29+
schema:
30+
$ref: '#/components/schemas/ResourceResult'
31+
"500":
32+
description: 'Some internal error'
33+
content:
34+
application/json:
35+
schema:
36+
$ref: '#/components/schemas/ErrorResult'
37+
get:
38+
tags:
39+
- Resource
40+
summary: "Get list of resource"
41+
description: "Get list of resource"
42+
parameters:
43+
- in: query
44+
name: "filter"
45+
description: "Returning orders with by a specific filter."
46+
required: false
47+
schema:
48+
type: string
49+
responses:
50+
"200":
51+
description: "Success"
52+
content:
53+
application/json:
54+
schema:
55+
$ref: "#/components/schemas/ResourceListResult"
56+
'500':
57+
description: "Internal error"
58+
content:
59+
application/json:
60+
schema:
61+
$ref: '#/components/schemas/ErrorResult'
62+
"/resource/{id}":
63+
get:
64+
tags:
65+
- Resource
66+
summary: 'Get info about specific resource'
67+
description: "Returns information of resource by id"
68+
parameters:
69+
- in: path
70+
name: id
71+
description: Id of resource
72+
required: true
73+
schema:
74+
type: string
75+
responses:
76+
"200":
77+
description: 'Success'
78+
content:
79+
application/json:
80+
schema:
81+
$ref: '#/components/schemas/ResourceResult'
82+
"500":
83+
description: 'Some internal error'
84+
content:
85+
application/json:
86+
schema:
87+
$ref: '#/components/schemas/ErrorResult'
88+
components:
89+
schemas:
90+
# Basic results components
91+
ErrorResult:
92+
type: object
93+
properties:
94+
messages:
95+
type: array
96+
items:
97+
$ref: "#/components/schemas/Message"
98+
description: "Message field is not required"
99+
Message:
100+
type: object
101+
properties:
102+
level:
103+
type: string
104+
enum:
105+
- emergency
106+
- alert
107+
- critical
108+
- error
109+
- warning
110+
- notice
111+
- info
112+
type:
113+
type: string
114+
enum:
115+
- UNDEFINED
116+
- LOGGER_MESSAGE
117+
- INVALID_RESPONSE # To test that you can duplicate reserved types to manifest, do not add this type to real manifests
118+
description: >
119+
You can expose this enum for all your errors
120+
UNDEFINED - Any undefined message type
121+
LOGGER_MESSAGE - Same as undefined
122+
text:
123+
type: string
124+
description: Message, that describes what went wrong
125+
SuccessResult:
126+
allOf:
127+
- $ref: '#/components/schemas/ErrorResult'
128+
type: object
129+
properties:
130+
data:
131+
type: object
132+
133+
## One resource result
134+
ResourceResult:
135+
allOf:
136+
- $ref: '#/components/schemas/SuccessResult'
137+
type: object
138+
properties:
139+
data:
140+
$ref: '#/components/schemas/Resource'
141+
142+
## Result with list of resource
143+
ResourceListResult:
144+
allOf:
145+
- $ref: '#/components/schemas/SuccessResult'
146+
type: object
147+
properties:
148+
data:
149+
type: array
150+
items:
151+
$ref: '#/components/schemas/Resource'
152+
153+
## Body for post request
154+
ResourcePostRequest:
155+
type: object
156+
required:
157+
- requiredField
158+
properties:
159+
requiredField:
160+
type: string
161+
description: required
162+
optionalField:
163+
type: string
164+
nullable: true
165+
description: optional
166+
167+
## Resource object
168+
Resource:
169+
type: object
170+
properties:
171+
id:
172+
type: string
173+
description: Unique identificator of order (generated by server).
174+
example: "AP7734"
175+
requiredField:
176+
type: string
177+
description: Order number received from supplier
178+
optionalField:
179+
type: string
180+
nullable: true
181+
example: null
182+
objectField:
183+
$ref: '#/components/schemas/NestedObject'
184+
arrayField:
185+
type: array
186+
description: List of ordered products
187+
items:
188+
$ref: '#/components/schemas/NestedObject'
189+
190+
NestedObject:
191+
type: object
192+
properties:
193+
name:
194+
type: string
195+
description: Some name
196+
example: "name"

0 commit comments

Comments
 (0)