[{"data":1,"prerenderedAt":170},["Reactive",2],{"/guides/go/go-resty/avoid-conversion-on-error":3,"related:dvJPmg1nwb":88},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"property":12,"output":13,"related":14,"default":6,"body":16,"_type":83,"_id":84,"_source":85,"_file":86,"_extension":87},"/guides/go/go-resty/avoid-conversion-on-error","go-resty",false,"","Avoid the conversion on error when loading the document","Learn how to avoid the conversion on error when loading the document using Go and the Go-Resty library and relies on the PDFShift's API.","Go","Go-Resty","raise_for_status","pdf",[15],"convert-html-to-pdf-from-raw-html",{"type":17,"children":18,"toc":80},"root",[19,27,48,60],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24],{"type":25,"value":26},"text","In this guide, we'll show you how to abort the conversion when loading the distant source does not return a 2XX response.",{"type":20,"tag":21,"props":28,"children":29},{},[30,32,38,40,46],{"type":25,"value":31},"When you're converting a document, you might want to avoid the conversion on error when loading the document. This can be done by setting the ",{"type":20,"tag":33,"props":34,"children":36},"code",{"className":35},[],[37],{"type":25,"value":12},{"type":25,"value":39}," parameter to ",{"type":20,"tag":33,"props":41,"children":43},{"className":42},[],[44],{"type":25,"value":45},"True",{"type":25,"value":47}," in the request.",{"type":20,"tag":49,"props":50,"children":55},"pre",{"className":51,"code":53,"language":54,"meta":7},[52],"language-go","package main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"io/ioutil\"\n    \"github.com/go-resty/resty/v2\"\n)\n\nfunc main() {\n    // You can get an API key at https://pdfshift.io\n    apiKey := \"sk_xxxxxxxxxxxx\"\n\n    params := map[string]interface{}{\n        \"source\":            \"https://www.httpstat.us/404\",\n        \"raise_for_status\":  true,\n    }\n\n    // Marshal the parameters into JSON\n    jsonParams, err := json.Marshal(params)\n    if err != nil {\n        fmt.Println(\"Error marshaling JSON:\", err)\n        return\n    }\n    // Create a new Resty client\n    client := resty.New()\n\n    // Perform the request\n    resp, err := client.R().\n        SetHeader(\"Content-Type\", \"application/json\").\n        SetHeader(\"X-API-Key\", apiKey).\n        SetBody(jsonParams).\n        Post(\"https://api.pdfshift.io/v3/convert/pdf\")\n\n    if err != nil {\n        fmt.Println(\"Error performing request:\", err)\n        return\n    }\n\n    // Check response status code\n    if resp.StatusCode() >= 400 {\n        fmt.Printf(\"Request failed with status code %d: %s\\n\", resp.StatusCode(), string(resp.Body()))\n        return\n    }\n\n    // Save the PDF document\n    err = ioutil.WriteFile(\"result.pdf\", resp.Body(), 0644)\n    if err != nil {\n        fmt.Println(\"Error saving PDF document:\", err)\n        return\n    }\n\n    fmt.Println(\"The PDF document was generated and saved to result.pdf\")\n}\n","go",[56],{"type":20,"tag":33,"props":57,"children":58},{"__ignoreMap":7},[59],{"type":25,"value":53},{"type":20,"tag":21,"props":61,"children":62},{},[63,65,70,72,78],{"type":25,"value":64},"Passing ",{"type":20,"tag":33,"props":66,"children":68},{"className":67},[],[69],{"type":25,"value":12},{"type":25,"value":71}," to ",{"type":20,"tag":33,"props":73,"children":75},{"className":74},[],[76],{"type":25,"value":77},"true",{"type":25,"value":79}," will ensure that if PDFShift can not load your document, the conversion will fail with an error.",{"title":7,"searchDepth":81,"depth":81,"links":82},2,[],"markdown","content:guides:go:go-resty:avoid-conversion-on-error.md","content","guides/go/go-resty/avoid-conversion-on-error.md","md",[89,93,97,101,105,106,110,114,118,122,126,130,134,138,142,146,150,154,158,162,166],{"_path":90,"title":91,"language":10,"library":11,"_id":92},"/guides/go/go-resty/accessing-secured-pages","Accessing secured pages","content:guides:go:go-resty:accessing-secured-pages.md",{"_path":94,"title":95,"language":10,"library":11,"_id":96},"/guides/go/go-resty/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:go:go-resty:adding-a-custom-header-or-footer.md",{"_path":98,"title":99,"language":10,"library":11,"_id":100},"/guides/go/go-resty/adding-a-text-watermark","Adding a text watermark","content:guides:go:go-resty:adding-a-text-watermark.md",{"_path":102,"title":103,"language":10,"library":11,"_id":104},"/guides/go/go-resty/adding-an-image-watermark","Adding an image watermark","content:guides:go:go-resty:adding-an-image-watermark.md",{"_path":4,"title":8,"language":10,"library":11,"_id":84},{"_path":107,"title":108,"language":10,"library":11,"_id":109},"/guides/go/go-resty/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:go:go-resty:convert-html-to-pdf-from-a-url.md",{"_path":111,"title":112,"language":10,"library":11,"_id":113},"/guides/go/go-resty/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:go:go-resty:convert-html-to-pdf-from-raw-html.md",{"_path":115,"title":116,"language":10,"library":11,"_id":117},"/guides/go/go-resty/define-a-time-limit","Define a time limit","content:guides:go:go-resty:define-a-time-limit.md",{"_path":119,"title":120,"language":10,"library":11,"_id":121},"/guides/go/go-resty/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:go:go-resty:exporting-only-a-specific-set-of-pages.md",{"_path":123,"title":124,"language":10,"library":11,"_id":125},"/guides/go/go-resty/generate-a-document-with-full-height","Generate a document with full height","content:guides:go:go-resty:generate-a-document-with-full-height.md",{"_path":127,"title":128,"language":10,"library":11,"_id":129},"/guides/go/go-resty/loading-css-from-a-string","Loading CSS from a string","content:guides:go:go-resty:loading-css-from-a-string.md",{"_path":131,"title":132,"language":10,"library":11,"_id":133},"/guides/go/go-resty/loading-css-from-a-url","Loading CSS from a URL","content:guides:go:go-resty:loading-css-from-a-url.md",{"_path":135,"title":136,"language":10,"library":11,"_id":137},"/guides/go/go-resty/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:go:go-resty:loading-javascript-from-a-string.md",{"_path":139,"title":140,"language":10,"library":11,"_id":141},"/guides/go/go-resty/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:go:go-resty:loading-javascript-from-a-url.md",{"_path":143,"title":144,"language":10,"library":11,"_id":145},"/guides/go/go-resty/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:go:go-resty:protecting-the-generated-pdf.md",{"_path":147,"title":148,"language":10,"library":11,"_id":149},"/guides/go/go-resty/receive-a-webhook-event","Receive a webhook event","content:guides:go:go-resty:receive-a-webhook-event.md",{"_path":151,"title":152,"language":10,"library":11,"_id":153},"/guides/go/go-resty/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:go:go-resty:save-your-pdf-online-and-get-back-a-url.md",{"_path":155,"title":156,"language":10,"library":11,"_id":157},"/guides/go/go-resty/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:go:go-resty:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":159,"title":160,"language":10,"library":11,"_id":161},"/guides/go/go-resty/send-custom-http-headers","Send custom HTTP headers","content:guides:go:go-resty:send-custom-http-headers.md",{"_path":163,"title":164,"language":10,"library":11,"_id":165},"/guides/go/go-resty/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:go:go-resty:using-cookies.md",{"_path":167,"title":168,"language":10,"library":11,"_id":169},"/guides/go/go-resty/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:go:go-resty:waiting-for-a-custom-element-to-be-ready.md",1785426828705]