checkMsg returns whether the given message is a user message or a control message. If the status header is present, it returns an appropriate error based on the status code (404, etc.)
(msg *nats.Msg)
| 459 | // If the status header is present, it returns an appropriate error based |
| 460 | // on the status code (404, etc.) |
| 461 | func checkMsg(msg *nats.Msg) (bool, error) { |
| 462 | // If payload or no header, consider this a user message |
| 463 | if len(msg.Data) > 0 || len(msg.Header) == 0 { |
| 464 | return true, nil |
| 465 | } |
| 466 | // Look for status header |
| 467 | val := msg.Header.Get("Status") |
| 468 | descr := msg.Header.Get("Description") |
| 469 | // If not present, then this is considered a user message |
| 470 | if val == "" { |
| 471 | return true, nil |
| 472 | } |
| 473 | |
| 474 | switch val { |
| 475 | case statusBadRequest: |
| 476 | return false, ErrBadRequest |
| 477 | case statusNoResponders: |
| 478 | return false, nats.ErrNoResponders |
| 479 | case statusNoMsgs: |
| 480 | // 404 indicates that there are no messages. |
| 481 | return false, ErrNoMessages |
| 482 | case statusTimeout: |
| 483 | return false, nats.ErrTimeout |
| 484 | case statusControlMsg: |
| 485 | return false, nil |
| 486 | case statusPinIdMismatch: |
| 487 | return false, ErrPinIDMismatch |
| 488 | case statusConflict: |
| 489 | if strings.Contains(strings.ToLower(descr), maxBytesExceeded) { |
| 490 | return false, ErrMaxBytesExceeded |
| 491 | } |
| 492 | if strings.Contains(strings.ToLower(descr), batchCompleted) { |
| 493 | return false, ErrBatchCompleted |
| 494 | } |
| 495 | if strings.Contains(strings.ToLower(descr), consumerDeleted) { |
| 496 | return false, ErrConsumerDeleted |
| 497 | } |
| 498 | if strings.Contains(strings.ToLower(descr), leadershipChange) { |
| 499 | return false, ErrConsumerLeadershipChanged |
| 500 | } |
| 501 | if strings.Contains(strings.ToLower(descr), serverShutdown) { |
| 502 | return false, ErrServerShutdown |
| 503 | } |
| 504 | } |
| 505 | return false, fmt.Errorf("nats: %s", msg.Header.Get("Description")) |
| 506 | } |
| 507 | |
| 508 | func parsePending(msg *nats.Msg) (int, int, error) { |
| 509 | msgsLeftStr := msg.Header.Get("Nats-Pending-Messages") |