@@ -6,11 +6,9 @@ import (
6
6
"encoding/json"
7
7
"fmt"
8
8
"io"
9
- "mime"
10
9
"net/http"
11
10
"net/url"
12
11
"regexp"
13
- "strconv"
14
12
"strings"
15
13
"time"
16
14
@@ -323,31 +321,13 @@ func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.ExternalAut
323
321
}
324
322
err = json .NewDecoder (resp .Body ).Decode (& r )
325
323
if err != nil {
326
- mediaType ,_ ,err := mime .ParseMediaType (resp .Header .Get ("Content-Type" ))
327
- if err != nil {
328
- mediaType = "unknown"
329
- }
330
-
331
- // If the json fails to decode, do a best effort to return a better error.
332
- switch {
333
- case resp .StatusCode == http .StatusTooManyRequests :
334
- retryIn := "please try again later"
335
- resetIn := resp .Header .Get ("x-ratelimit-reset" )
336
- if resetIn != "" {
337
- // Best effort to tell the user exactly how long they need
338
- // to wait for.
339
- unix ,err := strconv .ParseInt (resetIn ,10 ,64 )
340
- if err == nil {
341
- waitFor := time .Unix (unix ,0 ).Sub (time .Now ().Truncate (time .Second ))
342
- retryIn = fmt .Sprintf (" retry after %s" ,waitFor .Truncate (time .Second ))
343
- }
344
- }
345
- // 429 returns a plaintext payload with a message.
346
- return nil ,xerrors .New (fmt .Sprintf ("rate limit hit, unable to authorize device. %s" ,retryIn ))
347
- case mediaType == "application/x-www-form-urlencoded" :
348
- return nil ,xerrors .Errorf ("%s payload response is form-url encoded, expected a json payload" ,resp .StatusCode )
324
+ // Some status codes do not return json payloads, and we should
325
+ // return a better error.
326
+ switch resp .StatusCode {
327
+ case http .StatusTooManyRequests :
328
+ return nil ,xerrors .New ("rate limit hit, unable to authorize device. please try again later" )
349
329
default :
350
- return nil ,fmt .Errorf ("status_code=%d, mediaType=%s : %w" ,resp .StatusCode , mediaType ,err )
330
+ return nil ,fmt .Errorf ("status_code=%d: %w" ,resp .StatusCode ,err )
351
331
}
352
332
}
353
333
if r .ErrorDescription != "" {