简体   繁体   English

我收到了(请求失败,状态码为 500)

[英]I'm getting (Request failed with status code 500)

I'm trying to post with an express api, but im getting:-我正在尝试使用快递 api 发布,但我得到:-

Error: Request failed with status code 500
at e.exports (createError.js:16)
at e.exports (settle.js:17)
at XMLHttpRequest.p.onreadystatechange (xhr.js:61)

I'm using nodemailer and mailgun to send this form to an email, I have two forms that im trying to send, one forms and its api are working perfectly, but im getting an error when sending the enquiry form. I'm using nodemailer and mailgun to send this form to an email, I have two forms that im trying to send, one forms and its api are working perfectly, but im getting an error when sending the enquiry form.

EnquiryForm.js查询表单.js

class EnquiryForm extends Component {
state = {
    companyname: '',
    name: '',
    address: '',
    postCode: '',
    country: '',
    city: '',
    email: '',
    telefon: '',
    message: '',
    payment: '',
    shipping: '',
    cart: JSON.parse(localStorage.getItem('dataArr')),
    errors: {}
}
/**            cart: this.state.cart */
onFormSubmit = async (event) => {
    event.preventDefault();
    this.setState({ errors: {} })
    const enquiryData = {
        companyname: this.state.companyname,
        name: this.state.name,
        email: this.state.email,
        telefon: this.state.telefon,
        message: this.state.message,
        address: this.state.address,
        postCode: this.state.postCode,
        country: this.state.country,
        city: this.state.city,
        payment: this.state.payment,
        shipping: this.state.shipping,
    }

    console.log(enquiryData);

    await axios.post('/enquirypost', enquiryData)
        .then(res => {
            console.log(res)
        })
        .catch(err => {
            console.log(err);
            this.setState({ errors: err.response.data })
        })
}

changeHandler = (event) => {
    this.setState({
        [event.target.name]: event.target.value
    })
}
render() {
    const productArray = JSON.parse(localStorage.getItem('dataArr'));
    const { errors } = this.state;
    return (
        <div className="EnquiryFormBackground" style={{ width: '100%', height: '100%' }}>
            <Card className="Enquiry-Form-Box" style={{ marginBottom: '4%' }}>
                <div className="Enquiry-Form-Box-top" style={{ textAlign: 'center' }}>
                    <span className="EnquiryFormTitle">PRODUCT LIST</span>
                    {productArray.map(d => (
                        <Card className="EnquiryProductRow" style={{ margin: '2% 2%' }} key={d.Heading}>
                            <div className="productCellF">
                                <img
                                    src={d.Img}
                                    alt='Product-image'
                                    className='imgCellF' />
                                <p className="textCellF">{d.Heading}</p>
                            </div>
                            <div className="tableCellF">
                                <p className="textCellF">&times;{d.Quantity === undefined ? 1 : d.Quantity}</p>

                            </div>
                            <div className="tableCellF">
                                <p className="textCellF">€{d.IngPrice}</p>
                            </div>
                        </Card>
                    ))}
                </div>
            </Card>
            <Card className="Enquiry-Form-Box">
                <div className="Enquiry-Form-Box-top" style={{ textAlign: 'center' }}>
                    <span className="EnquiryFormTitle">ENQUIRY FORM</span>
                </div>
                <form onSubmit={this.onFormSubmit}>
                    <TextField
                        classes={{ margin: ' 2% 10%' }}
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="Firmenname"
                        color="primary"
                        name="companyname"
                        type="text"
                        onChange={this.changeHandler}
                        helperText={errors.companyname}
                        error={errors.companyname ? true : false}
                        required
                    />
                    <TextField
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="Name"
                        color="primary"
                        name="name"
                        type="text"
                        onChange={this.changeHandler}
                        helperText={errors.name}
                        error={errors.companyname ? true : false}
                        required
                    />
                    <TextField
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="Adresse"
                        color="primary"
                        name="address"
                        type="text"
                        onChange={this.changeHandler}
                    />
                    <TextField
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="Postleitzahl"
                        color="primary"
                        name="postCode"
                        type="text"
                        onChange={this.changeHandler}
                    />
                    <Select
                        className="Enquiry-Form-Input"
                        native
                        label="Land"
                        color="primary"
                        name="country"
                        onChange={this.changeHandler}
                        helperText={errors.country}
                        error={errors.companyname ? true : false}
                        required
                    >
                        {countryList.getNames().map(e => (
                            <option key={e}>{e}</option>
                        ))}
                    </Select>
                    <TextField
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="Stadt"
                        color="primary"
                        name="city"
                        type="text"
                        onChange={this.changeHandler}
                    />
                    <TextField
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="E-Mail"
                        color="primary"
                        name="email"
                        type="email"
                        onChange={this.changeHandler}
                        helperText={errors.email}
                        error={errors.companyname ? true : false}
                        required
                    />
                    <TextField
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="Telefon"
                        color="primary"
                        name="telefon"
                        type="text"
                        onChange={this.changeHandler}
                    />
                    <TextField
                        className="Enquiry-Form-Input"
                        id="standard-secondary"
                        label="Ihre Nachricht"
                        color="primary"
                        name="message"
                        type="text"
                        onChange={this.changeHandler}
                        variant="outlined"
                        multiline
                        rows={4}
                    />
                    <div className="Enquiry-Form-Box-top">
                        <span className="EnquiryFormTitle">SHIPPING</span>
                    </div>
                    <RadioGroup
                        className="Enquiry-Form-Input"
                        aria-label="shipping"
                        name="shipping"
                        onChange={this.changeHandler}
                        helperText={errors.shipping}
                        error={errors.companyname ? true : false}>
                        <FormControlLabel className="EnquiryFormRadioBtn" value="DHL" control={<Radio />} label="DHL" />
                        <FormControlLabel className="EnquiryFormRadioBtn" value="Spedition" control={<Radio />} label="Spedition" />
                    </RadioGroup>
                    <div className="Enquiry-Form-Box-top">
                        <span className="EnquiryFormTitle">PAYMENT</span>
                    </div>
                    <RadioGroup
                        className="Enquiry-Form-Input"
                        aria-label="payment"
                        name="payment"
                        onChange={this.changeHandler}
                        helperText={errors.payment}
                        error={errors.companyname ? true : false}>
                        <FormControlLabel className="EnquiryFormRadioBtn" value="VorkasseWir teilen Ihnen die Gesamtkosten inkl. Versand mit und Sie überweisen dann per Vorkasse" control={<Radio />} label="VorkasseWir teilen Ihnen die Gesamtkosten inkl. Versand mit und Sie überweisen dann per Vorkasse" />
                        <FormControlLabel className="EnquiryFormRadioBtn" value="PaypalWir teilen Ihnen die Gesamtosten inkl. Versand mit und Sie überweisen dann mit Paypal" control={<Radio />} label="PaypalWir teilen Ihnen die Gesamtosten inkl. Versand mit und Sie überweisen dann mit Paypal" />
                    </RadioGroup>
                    <Button
                        variant="contained"
                        color="primary"
                        type="submit"
                        className="EnquiryFormBtn">
                        <span className="EnquiryFormBtnTitle">
                            Submit
                        </span>
                    </Button>
                </form>
            </Card>
        </div >
    )
}
 }

export default EnquiryForm

I'm not sure if its a problem with the backend or frontend我不确定是后端还是前端的问题

this is my express api:-这是我的快递 api:-

app.post('/enquirypost', (req, res) => {
//SENDING EMAIL
const data = {
    companyname: req.body.companyname,
    name: req.body.name,
    email: req.body.email,
    telefon: req.body.telefon,
    message: req.body.message,
    address: req.body.address,
    postCode: req.body.postCode,
    country: req.body.country,
    city: req.body.city,
    payment: req.body.payment,
    shipping: req.body.shipping
};
console.log(data);


const { valid, errors } = enquiryCheck(data);
if (!valid) return res.status(400).json(errors);

const html = `
    <h3>Contact Details</h3>
    <ul>
        <li>company name: ${data.companyname}</li>
        <li>name: ${data.name}</li>
        <li>email: ${data.email}</li>
        <li>telefon: ${data.telefon}</li>
        <li>address: ${data.address}</li>
        <li>postCode: ${data.postCode}</li>
        <li>country: ${data.country}</li>
        <li>city: ${data.city}</li>
        <li>payment: ${data.payment}</li>
        <li>shipping: ${data.shipping}</li>
    </ul>
    <h3>Message</h3>
    <p>${data.message}</p>
`;

console.log(req.body);
sendEnquiry(data.email, data.message, html, (err, data) => {
    if (err) {
        res.status(500).json({ message: 'Internal Error' })
    } else {
        res.json({ message: 'Email Sent!!!' })
    }
})

}) })

HTTP 500 means internal server error;HTTP 500表示服务器内部错误; and the api is responsible for handling that; api负责处理该问题; it could be front-end (you) sending a malformed request and they didn't handle that case which raised an exception in server or there is actually a logical error on back-end side needed to be fixed;可能是前端(您)发送了格式错误的请求,但他们没有处理在服务器中引发异常的情况,或者后端实际上存在逻辑错误需要修复; anyway you shouldn't receive 500 status from a server even if you are sending malformed request.无论如何,即使您发送格式错误的请求,您也不应该从服务器收到500状态。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 nodejs - AxiosError:请求失败,状态码为 500 - nodejs - AxiosError: Request failed with status code 500 Axios - 未捕获(承诺)错误:请求失败,状态码为 500 - Axios - Uncaught (in promise) Error: Request failed with status code 500 当我发送带有图像的发布请求时得到这个:错误:请求失败,状态码 409 - Getting this with when I send a post request with an image: Error: Request failed with status code 409 我想获取我的 Graph API 令牌,但出现错误,我正在使用 HttpServices 发出 POST 请求。 我收到 400 状态码。 我正在使用 NestJS - I want to get my Graph API token but I got an error, I'm making a POST request with HttpServices. I'm getting a 400 status code. I'm using NestJS 使用 axios get 获取请求失败,状态码为 403 - Getting Request failed with status code 403 with axios get 错误:“请求失败,状态代码为500” con laravel en axios.put() - Error: “Request failed with status code 500” con laravel en axios.put() 重新加载页面时如何修复请求失败,状态码为 500 - How to fix the Request failed with status code 500 when reload page in react IncomingMessage.handleStreamEnd Express.js 的 POST 请求失败,状态码为 500 - POST Request failed with status code 500 at IncomingMessage.handleStreamEnd Express.js GET http://localhost:3000/posts/timeline/(objId) 500 (Internal Server Error) - Uncaught (in promise) AxiosError {'Request failed with status code 500' - GET http://localhost:3000/posts/timeline/(objId) 500 (Internal Server Error) - Uncaught (in promise) AxiosError {'Request failed with status code 500' 服务器曾经可以工作,再次部署后(经过很长时间),我在对服务器的任何请求时都会收到状态代码 503 - Server used to work, after deployed again (after long time) i'm getting Status Code 503 on any request to the server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM