mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
Merge pull request #10 from capcom6/feature/errors-logging
Added: errors logging
This commit is contained in:
commit
3248c1e93e
@ -1,5 +1,4 @@
|
||||
@baseUrl=http://localhost:3000
|
||||
@cloudUrl=https://sms.capcom.me
|
||||
@baseUrl={{$dotenv CLOUD__URL}}
|
||||
@credentials={{$dotenv CLOUD__CREDENTIALS}}
|
||||
@mobileToken={{$dotenv MOBILE__TOKEN}}
|
||||
@phone={{$dotenv PHONE}}
|
||||
@ -24,11 +23,11 @@ Authorization: Basic {{credentials}}
|
||||
"phoneNumbers": [
|
||||
"{{phone}}"
|
||||
],
|
||||
"simNumber": 2
|
||||
"simNumber": 3
|
||||
}
|
||||
|
||||
###
|
||||
GET {{cloudUrl}}/api/3rdparty/v1/message/Cao6mzuIRrjBB7TtlWnZ- HTTP/1.1
|
||||
GET {{baseUrl}}/api/3rdparty/v1/message/IyJP8Iexf55XFhYFHMjcs HTTP/1.1
|
||||
Authorization: Basic {{credentials}}
|
||||
|
||||
###
|
||||
|
||||
@ -493,6 +493,11 @@
|
||||
"state"
|
||||
],
|
||||
"properties": {
|
||||
"error": {
|
||||
"description": "Ошибка",
|
||||
"type": "string",
|
||||
"example": "timeout"
|
||||
},
|
||||
"phoneNumber": {
|
||||
"description": "Номер телефона",
|
||||
"type": "string",
|
||||
|
||||
@ -135,6 +135,10 @@ definitions:
|
||||
- MessageStateFailed
|
||||
smsgateway.RecipientState:
|
||||
properties:
|
||||
error:
|
||||
description: Ошибка
|
||||
example: timeout
|
||||
type: string
|
||||
phoneNumber:
|
||||
description: Номер телефона
|
||||
example: "79990001234"
|
||||
|
||||
10
db/migrations/20231127234448_error_reporting.sql
Normal file
10
db/migrations/20231127234448_error_reporting.sql
Normal file
@ -0,0 +1,10 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
ALTER TABLE `message_recipients`
|
||||
ADD `error` varchar(256);
|
||||
-- +goose StatementEnd
|
||||
---
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
ALTER TABLE `message_recipients` DROP `error`;
|
||||
-- +goose StatementEnd
|
||||
@ -60,4 +60,5 @@ type MessageRecipient struct {
|
||||
MessageID uint64 `gorm:"primaryKey;type:BIGINT UNSIGNED"`
|
||||
PhoneNumber string `gorm:"primaryKey;type:varchar(16)"`
|
||||
State MessageState `gorm:"not null;type:enum('Pending','Sent','Processed','Delivered','Failed');default:Pending"`
|
||||
Error *string `gorm:"type:varchar(256)"`
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ func (r *MessagesRepository) UpdateState(message *models.Message) error {
|
||||
}
|
||||
|
||||
for _, v := range message.Recipients {
|
||||
if err := tx.Model(&v).Where("message_id = ? AND phone_number = ?", message.ID, v.PhoneNumber).Update("state", v.State).Error; err != nil {
|
||||
if err := tx.Model(&v).Where("message_id = ?", message.ID).Select("State", "Error").Updates(&v).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,10 @@ import (
|
||||
"github.com/nyaruka/phonenumbers"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorTTLExpired = "TTL expired"
|
||||
)
|
||||
|
||||
var ErrValidation error = errors.New("validation error")
|
||||
|
||||
type MessagesService struct {
|
||||
@ -166,6 +170,7 @@ func (s *MessagesService) filterTimeouted(messages []models.Message) []models.Me
|
||||
v.State = models.MessageStateFailed
|
||||
for i := range v.Recipients {
|
||||
v.Recipients[i].State = models.MessageStateFailed
|
||||
v.Recipients[i].Error = types.AsPointer(ErrorTTLExpired)
|
||||
}
|
||||
s.Messages.UpdateState(&v)
|
||||
}
|
||||
@ -211,6 +216,7 @@ func (s *MessagesService) recipientsStateToModel(input []smsgateway.RecipientSta
|
||||
output[i] = models.MessageRecipient{
|
||||
PhoneNumber: phoneNumber,
|
||||
State: models.MessageState(v.State),
|
||||
Error: v.Error,
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,6 +235,7 @@ func modelToRecipientState(input models.MessageRecipient) smsgateway.RecipientSt
|
||||
return smsgateway.RecipientState{
|
||||
PhoneNumber: input.PhoneNumber,
|
||||
State: smsgateway.ProcessState(input.State),
|
||||
Error: input.Error,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,4 +30,5 @@ type MessageState struct {
|
||||
type RecipientState struct {
|
||||
PhoneNumber string `json:"phoneNumber" validate:"required,min=10" example:"79990001234"` // Номер телефона
|
||||
State ProcessState `json:"state" validate:"required" example:"Pending"` // Состояние
|
||||
Error *string `json:"error,omitempty" example:"timeout"` // Ошибка
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user