-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_problems.go
More file actions
569 lines (485 loc) · 16.4 KB
/
Copy pathstatus_problems.go
File metadata and controls
569 lines (485 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
package problemjson
import "net/http"
func apply(p *Problem, options []Option) {
for _, opt := range options {
opt(p)
}
}
// 4xx
// BadRequest returns a 400 Problem indicating the server could not understand
// the request due to malformed syntax.
func BadRequest(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/400",
Title: "Bad Request",
Status: http.StatusBadRequest,
Detail: "The request could not be understood by the server due to malformed syntax.",
}
apply(p, options)
return p
}
// Unauthorized returns a 401 Problem indicating authentication is required.
func Unauthorized(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/401",
Title: "Unauthorized",
Status: http.StatusUnauthorized,
Detail: "The request requires user authentication.",
}
apply(p, options)
return p
}
// PaymentRequired returns a 402 Problem indicating payment is required to
// access the requested resource.
func PaymentRequired(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/402",
Title: "Payment Required",
Status: http.StatusPaymentRequired,
Detail: "Payment is required to access the requested resource.",
}
apply(p, options)
return p
}
// Forbidden returns a 403 Problem indicating the caller lacks permission to
// access the requested resource.
func Forbidden(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/403",
Title: "Forbidden",
Status: http.StatusForbidden,
Detail: "You do not have permission to access the requested resource.",
}
apply(p, options)
return p
}
// NotFound returns a 404 Problem indicating the requested resource does not exist.
func NotFound(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/404",
Title: "Not Found",
Status: http.StatusNotFound,
Detail: "The requested resource could not be found.",
}
apply(p, options)
return p
}
// MethodNotAllowed returns a 405 Problem indicating the HTTP method is not
// permitted for the requested resource.
func MethodNotAllowed(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/405",
Title: "Method Not Allowed",
Status: http.StatusMethodNotAllowed,
Detail: "The requested method is not allowed for the requested resource.",
}
apply(p, options)
return p
}
// NotAcceptable returns a 406 Problem indicating the server cannot produce a
// response matching the Accept headers sent by the client.
func NotAcceptable(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/406",
Title: "Not Acceptable",
Status: http.StatusNotAcceptable,
Detail: "The requested resource is not available in a format acceptable to you.",
}
apply(p, options)
return p
}
// ProxyAuthRequired returns a 407 Problem indicating the client must first
// authenticate with a proxy.
func ProxyAuthRequired(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/407",
Title: "Proxy Authentication Required",
Status: http.StatusProxyAuthRequired,
Detail: "Authentication is required to access the requested resource through a proxy.",
}
apply(p, options)
return p
}
// RequestTimeout returns a 408 Problem indicating the client did not send a
// complete request within the server's timeout window.
func RequestTimeout(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/408",
Title: "Request Timeout",
Status: http.StatusRequestTimeout,
Detail: "The server timed out waiting for the request.",
}
apply(p, options)
return p
}
// Conflict returns a 409 Problem indicating the request conflicts with the
// current state of the resource.
func Conflict(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/409",
Title: "Conflict",
Status: http.StatusConflict,
Detail: "The request could not be completed due to a conflict with the current state of the resource.",
}
apply(p, options)
return p
}
// Gone returns a 410 Problem indicating the resource has been permanently removed.
func Gone(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/410",
Title: "Gone",
Status: http.StatusGone,
Detail: "The requested resource is no longer available.",
}
apply(p, options)
return p
}
// LengthRequired returns a 411 Problem indicating the request must include a
// Content-Length header.
func LengthRequired(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/411",
Title: "Length Required",
Status: http.StatusLengthRequired,
Detail: "A required length header was missing in the request.",
}
apply(p, options)
return p
}
// PreconditionFailed returns a 412 Problem indicating one or more request
// preconditions evaluated to false on the server.
func PreconditionFailed(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/412",
Title: "Precondition Failed",
Status: http.StatusPreconditionFailed,
Detail: "The server does not meet one of the preconditions specified in the request.",
}
apply(p, options)
return p
}
// PayloadTooLarge returns a 413 Problem indicating the request body exceeds
// the limit the server is willing to process.
func PayloadTooLarge(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/413",
Title: "Payload Too Large",
Status: http.StatusRequestEntityTooLarge,
Detail: "The request payload is too large.",
}
apply(p, options)
return p
}
// URITooLong returns a 414 Problem indicating the request URI is longer than
// the server can interpret.
func URITooLong(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/414",
Title: "URI Too Long",
Status: http.StatusRequestURITooLong,
Detail: "The requested URI is too long.",
}
apply(p, options)
return p
}
// UnsupportedMediaType returns a 415 Problem indicating the request's
// Content-Type is not supported by the server or resource.
func UnsupportedMediaType(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/415",
Title: "Unsupported Media Type",
Status: http.StatusUnsupportedMediaType,
Detail: "The request entity has a media type which the server or resource does not support.",
}
apply(p, options)
return p
}
// RangeNotSatisfiable returns a 416 Problem indicating the Range header in
// the request cannot be satisfied by the resource.
func RangeNotSatisfiable(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/416",
Title: "Range Not Satisfiable",
Status: http.StatusRequestedRangeNotSatisfiable,
Detail: "The request cannot be fulfilled as the range is not satisfiable.",
}
apply(p, options)
return p
}
// ExpectationFailed returns a 417 Problem indicating the server cannot meet
// the expectation declared in an Expect request header.
func ExpectationFailed(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/417",
Title: "Expectation Failed",
Status: http.StatusExpectationFailed,
Detail: "The server could not meet the expectation given in the request.",
}
apply(p, options)
return p
}
// Teapot returns a 418 Problem. The server refuses to brew coffee because it
// is, permanently, a teapot (RFC 2324).
func Teapot(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/418",
Title: "I'm a teapot",
Status: http.StatusTeapot,
Detail: "I'm a teapot, not a coffee machine.",
}
apply(p, options)
return p
}
// MisdirectedRequest returns a 421 Problem indicating the request was directed
// at a server that cannot produce a response for this URI.
func MisdirectedRequest(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/421",
Title: "Misdirected Request",
Status: http.StatusMisdirectedRequest,
Detail: "The server cannot produce a response for this request.",
}
apply(p, options)
return p
}
// UnprocessableEntity returns a 422 Problem indicating the request is
// well-formed but contains semantic errors the server cannot process.
func UnprocessableEntity(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/422",
Title: "Unprocessable Entity",
Status: http.StatusUnprocessableEntity,
Detail: "The request was well-formed but could not be followed due to semantic errors.",
}
apply(p, options)
return p
}
// Locked returns a 423 Problem indicating the requested resource is locked.
func Locked(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/423",
Title: "Locked",
Status: http.StatusLocked,
Detail: "The requested resource is locked.",
}
apply(p, options)
return p
}
// FailedDependency returns a 424 Problem indicating the request failed because
// it depended on another request that failed.
func FailedDependency(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/424",
Title: "Failed Dependency",
Status: http.StatusFailedDependency,
Detail: "The request failed due to a failure of a previous request.",
}
apply(p, options)
return p
}
// TooEarly returns a 425 Problem indicating the server is unwilling to risk
// processing a request that might be replayed.
func TooEarly(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/425",
Title: "Too Early",
Status: http.StatusTooEarly,
Detail: "The server is unwilling to risk processing a request that might be replayed.",
}
apply(p, options)
return p
}
// UpgradeRequired returns a 426 Problem indicating the client must switch to a
// different protocol before the server will fulfill the request.
func UpgradeRequired(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/426",
Title: "Upgrade Required",
Status: http.StatusUpgradeRequired,
Detail: "The client should switch to a different protocol.",
}
apply(p, options)
return p
}
// PreconditionRequired returns a 428 Problem indicating the server requires
// the request to be conditional.
func PreconditionRequired(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/428",
Title: "Precondition Required",
Status: http.StatusPreconditionRequired,
Detail: "The server requires a precondition in the request.",
}
apply(p, options)
return p
}
// TooManyRequests returns a 429 Problem indicating the caller has exceeded the
// allowed rate limit.
func TooManyRequests(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/429",
Title: "Too Many Requests",
Status: http.StatusTooManyRequests,
Detail: "You have sent too many requests in a given amount of time.",
}
apply(p, options)
return p
}
// RequestHeaderFieldsTooLarge returns a 431 Problem indicating one or more
// request header fields exceed the server's size limits.
func RequestHeaderFieldsTooLarge(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/431",
Title: "Request Header Fields Too Large",
Status: http.StatusRequestHeaderFieldsTooLarge,
Detail: "The server refuses to process the request because the header fields are too large.",
}
apply(p, options)
return p
}
// UnavailableForLegalReasons returns a 451 Problem indicating the resource
// cannot be served for legal reasons.
func UnavailableForLegalReasons(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/451",
Title: "Unavailable For Legal Reasons",
Status: http.StatusUnavailableForLegalReasons,
Detail: "The requested resource is unavailable due to legal reasons.",
}
apply(p, options)
return p
}
// 5xx
// InternalServerError returns a 500 Problem indicating an unexpected condition
// prevented the server from fulfilling the request.
func InternalServerError(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/500",
Title: "Internal Server Error",
Status: http.StatusInternalServerError,
Detail: "The server encountered an internal error and was unable to complete your request.",
}
apply(p, options)
return p
}
// NotImplemented returns a 501 Problem indicating the server does not support
// the functionality required to fulfill the request.
func NotImplemented(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/501",
Title: "Not Implemented",
Status: http.StatusNotImplemented,
Detail: "The server does not support the functionality required to fulfill the request.",
}
apply(p, options)
return p
}
// BadGateway returns a 502 Problem indicating the server received an invalid
// response from an upstream server while acting as a gateway.
func BadGateway(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/502",
Title: "Bad Gateway",
Status: http.StatusBadGateway,
Detail: "The server received an invalid response from an upstream server.",
}
apply(p, options)
return p
}
// ServiceUnavailable returns a 503 Problem indicating the server is temporarily
// unable to handle the request, typically due to overload or scheduled maintenance.
func ServiceUnavailable(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/503",
Title: "Service Unavailable",
Status: http.StatusServiceUnavailable,
Detail: "The server is currently unable to handle the request due to temporary overload or maintenance.",
}
apply(p, options)
return p
}
// GatewayTimeout returns a 504 Problem indicating the server, acting as a
// gateway, did not receive a timely response from an upstream server.
func GatewayTimeout(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/504",
Title: "Gateway Timeout",
Status: http.StatusGatewayTimeout,
Detail: "The server did not receive a timely response from an upstream server.",
}
apply(p, options)
return p
}
// HTTPVersionNotSupported returns a 505 Problem indicating the HTTP protocol
// version used in the request is not supported by the server.
func HTTPVersionNotSupported(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/505",
Title: "HTTP Version Not Supported",
Status: http.StatusHTTPVersionNotSupported,
Detail: "The server does not support the HTTP protocol version used in the request.",
}
apply(p, options)
return p
}
// VariantAlsoNegotiates returns a 506 Problem indicating that transparent
// content negotiation for the request results in a circular reference.
func VariantAlsoNegotiates(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/506",
Title: "Variant Also Negotiates",
Status: http.StatusVariantAlsoNegotiates,
Detail: "Transparent content negotiation for the request results in a circular reference.",
}
apply(p, options)
return p
}
// InsufficientStorage returns a 507 Problem indicating the server cannot store
// the representation needed to complete the request.
func InsufficientStorage(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/507",
Title: "Insufficient Storage",
Status: http.StatusInsufficientStorage,
Detail: "The server is unable to store the representation needed to complete the request.",
}
apply(p, options)
return p
}
// LoopDetected returns a 508 Problem indicating the server detected an infinite
// loop while processing the request.
func LoopDetected(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/508",
Title: "Loop Detected",
Status: http.StatusLoopDetected,
Detail: "The server detected an infinite loop while processing the request.",
}
apply(p, options)
return p
}
// NotExtended returns a 510 Problem indicating further extensions to the
// request are required for the server to fulfill it.
func NotExtended(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/510",
Title: "Not Extended",
Status: http.StatusNotExtended,
Detail: "Further extensions to the request are required for the server to fulfill it.",
}
apply(p, options)
return p
}
// NetworkAuthenticationRequired returns a 511 Problem indicating the client
// needs to authenticate to gain network access.
func NetworkAuthenticationRequired(options ...Option) *Problem {
p := &Problem{
Type: "https://httpstatuscodes.io/511",
Title: "Network Authentication Required",
Status: http.StatusNetworkAuthenticationRequired,
Detail: "Network authentication is required to access the requested resource.",
}
apply(p, options)
return p
}